|
interface | ByteIterator |
|
class | CodedBuilder |
|
class | LeafByteString |
|
class | Output |
|
Immutable sequence of bytes. Substring is supported by sharing the reference to the immutable underlying bytes, as with String. Concatenation is likewise supported without copying (long strings) by building a tree of pieces in RopeByteString.
Like String, the contents of a ByteString can never be observed to change, not even in the presence of a data race or incorrect API usage in the client code.
- Author
- crazy.nosp@m.bob@.nosp@m.googl.nosp@m.e.co.nosp@m.m Bob Lee
-
kento.nosp@m.n@go.nosp@m.ogle..nosp@m.com Kenton Varda
-
carla.nosp@m.nton.nosp@m.@goog.nosp@m.le.c.nosp@m.om Carl Haverl
-
marti.nosp@m.nrb@.nosp@m.googl.nosp@m.e.co.nosp@m.m Martin Buchholz
◆ asReadOnlyByteBuffer()
abstract ByteBuffer com.google.protobuf.ByteString.asReadOnlyByteBuffer |
( |
| ) |
|
|
abstract |
Constructs a read-only
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
- wrapped bytes
◆ asReadOnlyByteBufferList()
abstract List<ByteBuffer> com.google.protobuf.ByteString.asReadOnlyByteBufferList |
( |
| ) |
|
|
abstract |
Constructs a list of read-only
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
- a list of wrapped bytes
◆ byteAt()
abstract byte com.google.protobuf.ByteString.byteAt |
( |
int |
index | ) |
|
|
abstract |
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
-
- Returns
- the value
- Exceptions
-
IndexOutOfBoundsException | |
◆ concat()
Concatenate the given
to this one. Short concatenations, of total size smaller than ByteString#CONCATENATE_BY_COPY_SIZE, are produced by copying the underlying bytes (as per Rope.java, BAP95 . In general, the concatenate involves no copying.
- Parameters
-
other | string to concatenate |
- Returns
- a new instance
◆ copyFrom() [1/7]
static ByteString com.google.protobuf.ByteString.copyFrom |
( |
byte [] |
bytes, |
|
|
int |
offset, |
|
|
int |
size |
|
) |
| |
|
inlinestatic |
Copies the given bytes into a
.
- Parameters
-
bytes | source array |
offset | offset in source array |
size | number of bytes to copy |
- Returns
- new
◆ copyFrom() [2/7]
static ByteString com.google.protobuf.ByteString.copyFrom |
( |
byte [] |
bytes | ) |
|
|
inlinestatic |
Copies the given bytes into a
.
- Parameters
-
- Returns
- new
◆ copyFrom() [3/7]
static ByteString com.google.protobuf.ByteString.copyFrom |
( |
ByteBuffer |
bytes, |
|
|
int |
size |
|
) |
| |
|
inlinestatic |
Copies the next
bytes from a
into a
.
- Parameters
-
bytes | source buffer |
size | number of bytes to copy |
- Returns
- new
◆ copyFrom() [4/7]
static ByteString com.google.protobuf.ByteString.copyFrom |
( |
ByteBuffer |
bytes | ) |
|
|
inlinestatic |
Copies the remaining bytes from a
into a
.
- Parameters
-
- Returns
- new
◆ copyFrom() [5/7]
static ByteString com.google.protobuf.ByteString.copyFrom |
( |
String |
text, |
|
|
String |
charsetName |
|
) |
| throws UnsupportedEncodingException |
|
inlinestatic |
Encodes
into a sequence of bytes using the named charset and returns the result as a
.
- Parameters
-
text | source string |
charsetName | encoding to use |
- Returns
- new
- Exceptions
-
UnsupportedEncodingException | if the encoding isn't found |
◆ copyFrom() [6/7]
static ByteString com.google.protobuf.ByteString.copyFrom |
( |
String |
text, |
|
|
Charset |
charset |
|
) |
| |
|
inlinestatic |
Encodes
into a sequence of bytes using the named charset and returns the result as a
.
- Parameters
-
text | source string |
charset | encode using this charset |
- Returns
- new
◆ copyFrom() [7/7]
Concatenates all byte strings in the iterable and returns the result. This is designed to run in O(list size), not O(total bytes).
The returned
is not necessarily a unique object. If the list is empty, the returned object is the singleton empty
. If the list has only one element, that
will be returned without copying.
- Parameters
-
byteStrings | strings to be concatenated |
- Returns
- new
◆ copyFromUtf8()
static ByteString com.google.protobuf.ByteString.copyFromUtf8 |
( |
String |
text | ) |
|
|
inlinestatic |
Encodes
into a sequence of UTF-8 bytes and returns the result as a
.
- Parameters
-
- Returns
- new
◆ copyTo() [1/3]
void com.google.protobuf.ByteString.copyTo |
( |
byte [] |
target, |
|
|
int |
offset |
|
) |
| |
|
inline |
Copies bytes into a buffer at the given offset.
- Parameters
-
target | buffer to copy into |
offset | in the target buffer |
- Exceptions
-
IndexOutOfBoundsException | if the offset is negative or too large |
◆ copyTo() [2/3]
final void com.google.protobuf.ByteString.copyTo |
( |
byte [] |
target, |
|
|
int |
sourceOffset, |
|
|
int |
targetOffset, |
|
|
int |
numberToCopy |
|
) |
| |
|
inline |
Copies bytes into a buffer.
- Parameters
-
target | buffer to copy into |
sourceOffset | offset within these bytes |
targetOffset | offset within the target buffer |
numberToCopy | number of bytes to copy |
- Exceptions
-
IndexOutOfBoundsException | if an offset or size is negative or too large |
◆ copyTo() [3/3]
abstract void com.google.protobuf.ByteString.copyTo |
( |
ByteBuffer |
target | ) |
|
|
abstract |
Copies bytes into a ByteBuffer.
- Parameters
-
target | ByteBuffer to copy into. |
- Exceptions
-
java.nio.ReadOnlyBufferException | if the is read-only |
java.nio.BufferOverflowException | if the 's remaining() space is not large enough to hold the data. |
◆ copyToInternal()
abstract void com.google.protobuf.ByteString.copyToInternal |
( |
byte [] |
target, |
|
|
int |
sourceOffset, |
|
|
int |
targetOffset, |
|
|
int |
numberToCopy |
|
) |
| |
|
abstractprotected |
◆ endsWith()
Tests if this bytestring ends with the specified suffix. Similar to String#endsWith(String)
- Parameters
-
- Returns
true
if the byte sequence represented by the argument is a suffix of the byte sequence represented by this string; false
otherwise.
◆ equals()
abstract boolean com.google.protobuf.ByteString.equals |
( |
Object |
o | ) |
|
|
abstract |
◆ getTreeDepth()
abstract int com.google.protobuf.ByteString.getTreeDepth |
( |
| ) |
|
|
abstractprotected |
Return the depth of the tree representing this
, if any, whose root is this node. If this is a leaf node, return 0.
- Returns
- tree depth or zero
◆ hashCode()
final int com.google.protobuf.ByteString.hashCode |
( |
void |
| ) |
|
|
inline |
Compute the hashCode using the traditional algorithm from ByteString.
- Returns
- hashCode value
◆ isBalanced()
abstract boolean com.google.protobuf.ByteString.isBalanced |
( |
| ) |
|
|
abstractprotected |
Return
if this ByteString is literal (a leaf node) or a flat-enough tree in the sense of RopeByteString.
- Returns
- true if the tree is flat enough
◆ isEmpty()
Returns
if the size is
,
otherwise.
- Returns
- true if this is zero bytes long
◆ isValidUtf8()
abstract boolean com.google.protobuf.ByteString.isValidUtf8 |
( |
| ) |
|
|
abstract |
Tells whether this
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
whenever:
Arrays.equals(byteString.toByteArray(),
new String(byteString.toByteArray(),
"UTF-8").getBytes(
"UTF-8"))
This method returns
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
- whether the bytes in this are a well-formed UTF-8 byte sequence
◆ iterator()
◆ newCodedInput()
◆ newInput()
abstract InputStream com.google.protobuf.ByteString.newInput |
( |
| ) |
|
|
abstract |
◆ newOutput() [1/2]
static Output com.google.protobuf.ByteString.newOutput |
( |
int |
initialCapacity | ) |
|
|
inlinestatic |
◆ newOutput() [2/2]
static Output com.google.protobuf.ByteString.newOutput |
( |
| ) |
|
|
inlinestatic |
◆ partialHash()
abstract int com.google.protobuf.ByteString.partialHash |
( |
int |
h, |
|
|
int |
offset, |
|
|
int |
length |
|
) |
| |
|
abstractprotected |
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 | starting hash value |
offset | offset into this value to start looking at data values |
length | number of data values to include in the hash computation |
- Returns
- ending hash value
◆ partialIsValidUtf8()
abstract int com.google.protobuf.ByteString.partialIsValidUtf8 |
( |
int |
state, |
|
|
int |
offset, |
|
|
int |
length |
|
) |
| |
|
abstractprotected |
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
segments.
- Parameters
-
state | either (if this is the initial decoding operation) or the value returned from a call to a partial decoding method for the previous bytes |
offset | offset of the first byte to check |
length | number of bytes to check |
- Returns
- if the partial byte sequence is definitely malformed, 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.
◆ peekCachedHashCode()
final int com.google.protobuf.ByteString.peekCachedHashCode |
( |
| ) |
|
|
inlineprotected |
Return the cached hash code if available.
- Returns
- value of cached hash code or 0 if not computed yet
◆ readFrom() [1/3]
static ByteString com.google.protobuf.ByteString.readFrom |
( |
InputStream |
streamToDrain | ) |
throws IOException |
|
inlinestatic |
Completely reads the given stream's bytes into a
, blocking if necessary until all bytes are read through to the end of the stream.
Performance notes: The returned
is an immutable tree of byte arrays ("chunks") of the stream data. The first chunk is small, with subsequent chunks each being double the size, up to 8K.
Each byte read from the input stream will be copied twice to ensure that the resulting ByteString is truly immutable.
- Parameters
-
streamToDrain | The source stream, which is read completely but not closed. |
- Returns
- A new which is made up of chunks of various sizes, depending on the behavior of the underlying stream.
- Exceptions
-
IOException | IOException is thrown if there is a problem reading the underlying stream. |
◆ readFrom() [2/3]
static ByteString com.google.protobuf.ByteString.readFrom |
( |
InputStream |
streamToDrain, |
|
|
int |
chunkSize |
|
) |
| throws IOException |
|
inlinestatic |
Completely reads the given stream's bytes into a
, blocking if necessary until all bytes are read through to the end of the stream.
Performance notes: The returned
is an immutable tree of byte arrays ("chunks") of the stream data. The chunkSize parameter sets the size of these byte arrays.
Each byte read from the input stream will be copied twice to ensure that the resulting ByteString is truly immutable.
- Parameters
-
streamToDrain | The source stream, which is read completely but not closed. |
chunkSize | The size of the chunks in which to read the stream. |
- Returns
- A new which is made up of chunks of the given size.
- Exceptions
-
IOException | IOException is thrown if there is a problem reading the underlying stream. |
◆ readFrom() [3/3]
static ByteString com.google.protobuf.ByteString.readFrom |
( |
InputStream |
streamToDrain, |
|
|
int |
minChunkSize, |
|
|
int |
maxChunkSize |
|
) |
| throws IOException |
|
inlinestatic |
◆ size()
abstract int com.google.protobuf.ByteString.size |
( |
| ) |
|
|
abstract |
Gets the number of bytes.
- Returns
- size in bytes
◆ startsWith()
Tests if this bytestring starts with the specified prefix. Similar to String#startsWith(String)
- Parameters
-
- Returns
true
if the byte sequence represented by the argument is a prefix of the byte sequence represented by this string; false
otherwise.
◆ substring() [1/2]
final ByteString com.google.protobuf.ByteString.substring |
( |
int |
beginIndex | ) |
|
|
inline |
Return the substring from
, inclusive, to the end of the string.
- Parameters
-
beginIndex | start at this index |
- Returns
- substring sharing underlying data
- Exceptions
-
IndexOutOfBoundsException | if or . |
◆ substring() [2/2]
abstract ByteString com.google.protobuf.ByteString.substring |
( |
int |
beginIndex, |
|
|
int |
endIndex |
|
) |
| |
|
abstract |
Return the substring from
, inclusive, to
, exclusive.
- Parameters
-
beginIndex | start at this index |
endIndex | the last character is the one before this index |
- Returns
- substring sharing underlying data
- Exceptions
-
IndexOutOfBoundsException | if , , or . |
◆ toByteArray()
final byte [] com.google.protobuf.ByteString.toByteArray |
( |
| ) |
|
|
inline |
Copies bytes to a
.
- Returns
- copied bytes
◆ toString() [1/3]
final String com.google.protobuf.ByteString.toString |
( |
String |
charsetName | ) |
throws UnsupportedEncodingException |
|
inline |
Constructs a new
by decoding the bytes using the specified charset.
- Parameters
-
charsetName | encode using this charset |
- Returns
- new string
- Exceptions
-
UnsupportedEncodingException | if charset isn't recognized |
◆ toString() [2/3]
final String com.google.protobuf.ByteString.toString |
( |
Charset |
charset | ) |
|
|
inline |
Constructs a new
by decoding the bytes using the specified charset. Returns the same empty String if empty.
- Parameters
-
charset | encode using this charset |
- Returns
- new string
◆ toString() [3/3]
final String com.google.protobuf.ByteString.toString |
( |
| ) |
|
|
inline |
◆ toStringInternal()
abstract String com.google.protobuf.ByteString.toStringInternal |
( |
Charset |
charset | ) |
|
|
abstractprotected |
Constructs a new
by decoding the bytes using the specified charset.
- Parameters
-
charset | encode using this charset |
- Returns
- new string
◆ toStringUtf8()
final String com.google.protobuf.ByteString.toStringUtf8 |
( |
| ) |
|
|
inline |
Constructs a new
by decoding the bytes as UTF-8.
- Returns
- new string using UTF-8 encoding
◆ writeTo()
abstract void com.google.protobuf.ByteString.writeTo |
( |
OutputStream |
out | ) |
throws IOException |
|
abstract |
Writes a copy of the contents of this byte string to the specified output stream argument.
- Parameters
-
out | the output stream to which to write the data. |
- Exceptions
-
IOException | if an I/O error occurs. |
◆ EMPTY
The documentation for this class was generated from the following file:
- Source/ThirdParty/libwebrtc/Source/third_party/protobuf/java/core/src/main/java/com/google/protobuf/ByteString.java