Top Description Fields Constructors Methods
com.google.protobuf

pack-priv final Class NioByteString

extends LeafByteString
Class Inheritance
Static Imports
com.google.protobuf.Internal.checkNotNull

A ByteString that wraps around a ByteBuffer.

Field Summary

Modifier and TypeField and Description
private final ByteBuffer

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public ByteBuffer
asReadOnlyByteBuffer()

Implements abstract com.google.protobuf.ByteString.asReadOnlyByteBuffer.

Constructs a read-only java.nio.ByteBuffer whose content is equal to the contents of this byte string.
public List<ByteBuffer>
asReadOnlyByteBufferList()

Implements abstract com.google.protobuf.ByteString.asReadOnlyByteBufferList.

Constructs a list of read-only java.nio.ByteBuffer objects such that the concatenation of their contents is equal to the contents of this byte string.
public byte
byteAt(int
index of byte
index
)

Implements abstract com.google.protobuf.ByteString.byteAt.

Gets the byte at the given index.
public void
copyTo(ByteBuffer
ByteBuffer to copy into.
target
)

Implements abstract com.google.protobuf.ByteString.copyTo.

Copies bytes into a ByteBuffer.
protected void
copyToInternal(byte[] target, int sourceOffset, int targetOffset, int numberToCopy)

Implements abstract com.google.protobuf.ByteString.copyToInternal.

Internal (package private) implementation of copyTo(byte[], int, int, int).
public boolean
equals(Object
the reference object with which to compare.
other
)

Implements abstract com.google.protobuf.ByteString.equals.

Indicates whether some other object is "equal to" this one.
pack-priv boolean
equalsRange(ByteString
what to compare a substring in
other
,
int
offset into other
offset
,
int
number of bytes to compare
length
)

Implements abstract com.google.protobuf.ByteString.LeafByteString.equalsRange.

Check equality of the substring of given length of this object starting at zero with another ByteString substring starting at offset.
public byte
internalByteAt(int
index of byte
index
)

Implements abstract com.google.protobuf.ByteString.internalByteAt.

Gets the byte at the given index, assumes bounds checking has already been performed.
public boolean
isValidUtf8()

Implements abstract com.google.protobuf.ByteString.isValidUtf8.

Tells whether this ByteString represents a well-formed UTF-8 byte sequence, such that the original bytes can be converted to a String object and then round tripped back to bytes without loss.
public CodedInputStream
newCodedInput()

Implements abstract com.google.protobuf.ByteString.newCodedInput.

Creates a CodedInputStream which can be used to read the bytes.
public InputStream
newInput()

Implements abstract com.google.protobuf.ByteString.newInput.

Creates an InputStream which can be used to read the bytes.
protected int
partialHash(int
starting hash value
h
,
int
offset into this value to start looking at data values
offset
,
int
number of data values to include in the hash computation
length
)

Implements abstract com.google.protobuf.ByteString.partialHash.

Compute the hash across the value bytes starting with the given hash, and return the result.
protected int
partialIsValidUtf8(int
either 0 (if this is the initial decoding operation) or the value returned from a call to a partial decoding method for the previous bytes
state
,
int
offset of the first byte to check
offset
,
int
number of bytes to check
length
)

Implements abstract com.google.protobuf.ByteString.partialIsValidUtf8.

Tells whether the given byte sequence is a well-formed, malformed, or incomplete UTF-8 byte sequence.
private void
readObject(ObjectInputStream in)

Magic method that lets us override deserialization behavior.

public int
size()

Implements abstract com.google.protobuf.ByteString.size.

Gets the number of bytes.
private ByteBuffer

Returns:

the requested slice.
slice
(int
the beginning index of the slice (inclusive).
beginIndex
,
int
the end index of the slice (exclusive).
endIndex
)

Creates a slice of a range of this buffer.

public ByteString
substring(int
start at this index
beginIndex
,
int
the last character is the one before this index
endIndex
)

Implements abstract com.google.protobuf.ByteString.substring.

Return the substring from beginIndex, inclusive, to endIndex, exclusive.
protected String
toStringInternal(Charset
encode using this charset
charset
)

Implements abstract com.google.protobuf.ByteString.toStringInternal.

Constructs a new String by decoding the bytes using the specified charset.
private Object
writeReplace()

Magic method that lets us override serialization behavior.

public void
writeTo(OutputStream
the output stream to which to write the data.
out
)

Implements abstract com.google.protobuf.ByteString.writeTo.

Writes a copy of the contents of this byte string to the specified output stream argument.
pack-priv void
writeTo(ByteOutput
the output target to receive the bytes
output
)

Implements abstract com.google.protobuf.ByteString.writeTo.

Writes this ByteString to the provided ByteOutput.
pack-priv void
writeToInternal(OutputStream out, int sourceOffset, int numberToWrite)

Implements abstract com.google.protobuf.ByteString.writeToInternal.

Internal version of writeTo(OutputStream, int, int) that assumes all error checking has already been done.
Inherited from com.google.protobuf.ByteString.LeafByteString:
getTreeDepthisBalanced

Field Detail

bufferback to summary
private final ByteBuffer buffer

Constructor Detail

NioByteStringback to summary
pack-priv NioByteString(ByteBuffer buffer)

Method Detail

asReadOnlyByteBufferback to summary
public ByteBuffer asReadOnlyByteBuffer()

Implements abstract com.google.protobuf.ByteString.asReadOnlyByteBuffer.

Doc from com.google.protobuf.ByteString.asReadOnlyByteBuffer.

Constructs a read-only java.nio.ByteBuffer whose content is equal to the contents of this byte string. The result uses the same backing array as the byte string, if possible.

Returns:ByteBuffer

wrapped bytes

Annotations
@Override
asReadOnlyByteBufferListback to summary
public List<ByteBuffer> asReadOnlyByteBufferList()

Implements abstract com.google.protobuf.ByteString.asReadOnlyByteBufferList.

Doc from com.google.protobuf.ByteString.asReadOnlyByteBufferList.

Constructs a list of read-only java.nio.ByteBuffer objects such that the concatenation of their contents is equal to the contents of this byte string. The result uses the same backing arrays as the byte string.

By returning a list, implementations of this method may be able to avoid copying even when there are multiple backing arrays.

Returns:List<ByteBuffer>

a list of wrapped bytes

Annotations
@Override
byteAtback to summary
public byte byteAt(int index)

Implements abstract com.google.protobuf.ByteString.byteAt.

Doc from com.google.protobuf.ByteString.byteAt.

Gets the byte at the given index. This method should be used only for random access to individual bytes. To access bytes sequentially, use the ByteIterator returned by iterator(), and call substring(int, int) first if necessary.

Parameters
index:int

index of byte

Returns:byte

the value

Annotations
@Override
copyToback to summary
public void copyTo(ByteBuffer target)

Implements abstract com.google.protobuf.ByteString.copyTo.

Doc from com.google.protobuf.ByteString.copyTo.

Copies bytes into a ByteBuffer.

To copy a subset of bytes, you call this method on the return value of substring(int, int). Example: byteString.substring(start, end).copyTo(target)

Parameters
target:ByteBuffer

ByteBuffer to copy into.

Annotations
@Override
copyToInternalback to summary
protected void copyToInternal(byte[] target, int sourceOffset, int targetOffset, int numberToCopy)

Implements abstract com.google.protobuf.ByteString.copyToInternal.

Doc from com.google.protobuf.ByteString.copyToInternal.

Internal (package private) implementation of copyTo(byte[], int, int, int). It assumes that all error checking has already been performed and that numberToCopy > 0.

Annotations
@Override
equalsback to summary
public boolean equals(Object other)

Implements abstract com.google.protobuf.ByteString.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
other:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
equalsRangeback to summary
pack-priv boolean equalsRange(ByteString other, int offset, int length)

Implements abstract com.google.protobuf.ByteString.LeafByteString.equalsRange.

Doc from com.google.protobuf.ByteString.LeafByteString.equalsRange.

Check equality of the substring of given length of this object starting at zero with another ByteString substring starting at offset.

Parameters
other:ByteString

what to compare a substring in

offset:int

offset into other

length:int

number of bytes to compare

Returns:boolean

true for equality of substrings, else false.

Annotations
@Override
internalByteAtback to summary
public byte internalByteAt(int index)

Implements abstract com.google.protobuf.ByteString.internalByteAt.

Doc from com.google.protobuf.ByteString.internalByteAt.

Gets the byte at the given index, assumes bounds checking has already been performed.

Parameters
index:int

index of byte

Returns:byte

the value

Annotations
@Override
isValidUtf8back to summary
public boolean isValidUtf8()

Implements abstract com.google.protobuf.ByteString.isValidUtf8.

Doc from com.google.protobuf.ByteString.isValidUtf8.

Tells whether this ByteString represents a well-formed UTF-8 byte sequence, such that the original bytes can be converted to a String object and then round tripped back to bytes without loss.

More precisely, returns true whenever:

Arrays.equals(byteString.toByteArray(),
    new String(byteString.toByteArray(), "UTF-8").getBytes("UTF-8"))

This method returns false for "overlong" byte sequences, as well as for 3-byte sequences that would map to a surrogate character, in accordance with the restricted definition of UTF-8 introduced in Unicode 3.1. Note that the UTF-8 decoder included in Oracle's JDK has been modified to also reject "overlong" byte sequences, but (as of 2011) still accepts 3-byte surrogate character byte sequences.

See the Unicode Standard,
Table 3-6. UTF-8 Bit Distribution,
Table 3-7. Well Formed UTF-8 Byte Sequences.

Returns:boolean

whether the bytes in this ByteString are a well-formed UTF-8 byte sequence

Annotations
@Override
newCodedInputback to summary
public CodedInputStream newCodedInput()

Implements abstract com.google.protobuf.ByteString.newCodedInput.

Doc from com.google.protobuf.ByteString.newCodedInput.

Creates a CodedInputStream which can be used to read the bytes. Using this is often more efficient than creating a CodedInputStream that wraps the result of newInput().

Returns:CodedInputStream

stream based on wrapped data

Annotations
@Override
newInputback to summary
public InputStream newInput()

Implements abstract com.google.protobuf.ByteString.newInput.

Doc from com.google.protobuf.ByteString.newInput.

Creates an InputStream which can be used to read the bytes.

The InputStream returned by this method is guaranteed to be completely non-blocking. The method InputStream#available() returns the number of bytes remaining in the stream. The methods InputStream#read(byte[]), InputStream#read(byte[], int, int) and InputStream#skip(long) will read/skip as many bytes as are available. The method InputStream#markSupported() returns true.

The methods in the returned InputStream might not be thread safe.

Returns:InputStream

an input stream that returns the bytes of this byte string.

Annotations
@Override
partialHashback to summary
protected int partialHash(int h, int offset, int length)

Implements abstract com.google.protobuf.ByteString.partialHash.

Doc from com.google.protobuf.ByteString.partialHash.

Compute the hash across the value bytes starting with the given hash, and return the result. This is used to compute the hash across strings represented as a set of pieces by allowing the hash computation to be continued from piece to piece.

Parameters
h:int

starting hash value

offset:int

offset into this value to start looking at data values

length:int

number of data values to include in the hash computation

Returns:int

ending hash value

Annotations
@Override
partialIsValidUtf8back to summary
protected int partialIsValidUtf8(int state, int offset, int length)

Implements abstract com.google.protobuf.ByteString.partialIsValidUtf8.

Doc from com.google.protobuf.ByteString.partialIsValidUtf8.

Tells whether the given byte sequence is a well-formed, malformed, or incomplete UTF-8 byte sequence. This method accepts and returns a partial state result, allowing the bytes for a complete UTF-8 byte sequence to be composed from multiple ByteString segments.

Parameters
state:int

either 0 (if this is the initial decoding operation) or the value returned from a call to a partial decoding method for the previous bytes

offset:int

offset of the first byte to check

length:int

number of bytes to check

Returns:int

-1 if the partial byte sequence is definitely malformed, 0 if it is well-formed (no additional input needed), or, if the byte sequence is "incomplete", i.e. apparently terminated in the middle of a character, an opaque integer "state" value containing enough information to decode the character when passed to a subsequent invocation of a partial decoding method.

Annotations
@Override
readObjectback to summary
private void readObject(ObjectInputStream in) throws IOException

Magic method that lets us override deserialization behavior.

sizeback to summary
public int size()

Implements abstract com.google.protobuf.ByteString.size.

Doc from com.google.protobuf.ByteString.size.

Gets the number of bytes.

Returns:int

size in bytes

Annotations
@Override
sliceback to summary
private ByteBuffer slice(int beginIndex, int endIndex)

Creates a slice of a range of this buffer.

Parameters
beginIndex:int

the beginning index of the slice (inclusive).

endIndex:int

the end index of the slice (exclusive).

Returns:ByteBuffer

the requested slice.

substringback to summary
public ByteString substring(int beginIndex, int endIndex)

Implements abstract com.google.protobuf.ByteString.substring.

Doc from com.google.protobuf.ByteString.substring.

Return the substring from beginIndex, inclusive, to endIndex, exclusive.

Parameters
beginIndex:int

start at this index

endIndex:int

the last character is the one before this index

Returns:ByteString

substring sharing underlying data

Annotations
@Override
toStringInternalback to summary
protected String toStringInternal(Charset charset)

Implements abstract com.google.protobuf.ByteString.toStringInternal.

Doc from com.google.protobuf.ByteString.toStringInternal.

Constructs a new String by decoding the bytes using the specified charset.

Parameters
charset:Charset

encode using this charset

Returns:String

new string

Annotations
@Override
writeReplaceback to summary
private Object writeReplace()

Magic method that lets us override serialization behavior.

writeToback to summary
public void writeTo(OutputStream out) throws IOException

Implements abstract com.google.protobuf.ByteString.writeTo.

Doc from com.google.protobuf.ByteString.writeTo.

Writes a copy of the contents of this byte string to the specified output stream argument.

Parameters
out:OutputStream

the output stream to which to write the data.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs.
writeToback to summary
pack-priv void writeTo(ByteOutput output) throws IOException

Implements abstract com.google.protobuf.ByteString.writeTo.

Doc from com.google.protobuf.ByteString.writeTo.

Writes this ByteString to the provided ByteOutput. Calling this method may result in multiple operations on the target ByteOutput.

This method may expose internal backing buffers of the ByteString to the ByteOutput in order to avoid additional copying overhead. It would be possible for a malicious ByteOutput to corrupt the ByteString. Use with caution!

Parameters
output:ByteOutput

the output target to receive the bytes

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs
writeToInternalback to summary
pack-priv void writeToInternal(OutputStream out, int sourceOffset, int numberToWrite) throws IOException

Implements abstract com.google.protobuf.ByteString.writeToInternal.

Doc from com.google.protobuf.ByteString.writeToInternal.

Internal version of writeTo(OutputStream, int, int) that assumes all error checking has already been done.

Annotations
@Override