webkit  2cdf99a9e3038c7e01b3c37e8ad903ecbe5eecf1
https://github.com/WebKit/webkit
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
Classes | Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | List of all members
com.google.protobuf.ByteString Class Referenceabstract
Inheritance diagram for com.google.protobuf.ByteString:

Classes

interface  ByteIterator
 
class  CodedBuilder
 
class  LeafByteString
 
class  Output
 

Public Member Functions

abstract byte byteAt (int index)
 
final ByteIterator iterator ()
 
abstract int size ()
 
final boolean isEmpty ()
 
final ByteString substring (int beginIndex)
 
abstract ByteString substring (int beginIndex, int endIndex)
 
final boolean startsWith (ByteString prefix)
 
final boolean endsWith (ByteString suffix)
 
final ByteString concat (ByteString other)
 
void copyTo (byte[] target, int offset)
 
final void copyTo (byte[] target, int sourceOffset, int targetOffset, int numberToCopy)
 
abstract void copyTo (ByteBuffer target)
 
final byte [] toByteArray ()
 
abstract void writeTo (OutputStream out) throws IOException
 
abstract ByteBuffer asReadOnlyByteBuffer ()
 
abstract List< ByteBuffer > asReadOnlyByteBufferList ()
 
final String toString (String charsetName) throws UnsupportedEncodingException
 
final String toString (Charset charset)
 
final String toStringUtf8 ()
 
abstract boolean isValidUtf8 ()
 
abstract boolean equals (Object o)
 
final int hashCode ()
 
abstract InputStream newInput ()
 
abstract CodedInputStream newCodedInput ()
 
final String toString ()
 

Static Public Member Functions

static ByteString copyFrom (byte[] bytes, int offset, int size)
 
static ByteString copyFrom (byte[] bytes)
 
static ByteString copyFrom (ByteBuffer bytes, int size)
 
static ByteString copyFrom (ByteBuffer bytes)
 
static ByteString copyFrom (String text, String charsetName) throws UnsupportedEncodingException
 
static ByteString copyFrom (String text, Charset charset)
 
static ByteString copyFromUtf8 (String text)
 
static ByteString readFrom (InputStream streamToDrain) throws IOException
 
static ByteString readFrom (InputStream streamToDrain, int chunkSize) throws IOException
 
static ByteString readFrom (InputStream streamToDrain, int minChunkSize, int maxChunkSize) throws IOException
 
static ByteString copyFrom (Iterable< ByteString > byteStrings)
 
static Output newOutput (int initialCapacity)
 
static Output newOutput ()
 

Static Public Attributes

static final ByteString EMPTY = new LiteralByteString(Internal.EMPTY_BYTE_ARRAY)
 

Protected Member Functions

abstract void copyToInternal (byte[] target, int sourceOffset, int targetOffset, int numberToCopy)
 
abstract String toStringInternal (Charset charset)
 
abstract int partialIsValidUtf8 (int state, int offset, int length)
 
abstract int getTreeDepth ()
 
abstract boolean isBalanced ()
 
final int peekCachedHashCode ()
 
abstract int partialHash (int h, int offset, int length)
 

Detailed Description

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

Member Function Documentation

◆ asReadOnlyByteBuffer()

abstract ByteBuffer com.google.protobuf.ByteString.asReadOnlyByteBuffer ( )
abstract

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
wrapped bytes

◆ asReadOnlyByteBufferList()

abstract List<ByteBuffer> com.google.protobuf.ByteString.asReadOnlyByteBufferList ( )
abstract

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
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
indexindex of byte
Returns
the value
Exceptions
IndexOutOfBoundsException

◆ concat()

final ByteString com.google.protobuf.ByteString.concat ( ByteString  other)
inline

Concatenate the given

ByteString

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
otherstring to concatenate
Returns
a new
ByteString
instance

◆ copyFrom() [1/7]

static ByteString com.google.protobuf.ByteString.copyFrom ( byte []  bytes,
int  offset,
int  size 
)
inlinestatic

Copies the given bytes into a

ByteString

.

Parameters
bytessource array
offsetoffset in source array
sizenumber of bytes to copy
Returns
new
ByteString

◆ copyFrom() [2/7]

static ByteString com.google.protobuf.ByteString.copyFrom ( byte []  bytes)
inlinestatic

Copies the given bytes into a

ByteString

.

Parameters
bytesto copy
Returns
new
ByteString

◆ copyFrom() [3/7]

static ByteString com.google.protobuf.ByteString.copyFrom ( ByteBuffer  bytes,
int  size 
)
inlinestatic

Copies the next

bytes from a

java.nio.ByteBuffer

into a

ByteString

.

Parameters
bytessource buffer
sizenumber of bytes to copy
Returns
new
ByteString

◆ copyFrom() [4/7]

static ByteString com.google.protobuf.ByteString.copyFrom ( ByteBuffer  bytes)
inlinestatic

Copies the remaining bytes from a

java.nio.ByteBuffer

into a

ByteString

.

Parameters
bytessourceBuffer
Returns
new
ByteString

◆ 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

ByteString

.

Parameters
textsource string
charsetNameencoding to use
Returns
new
ByteString
Exceptions
UnsupportedEncodingExceptionif 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

ByteString

.

Parameters
textsource string
charsetencode using this charset
Returns
new
ByteString

◆ copyFrom() [7/7]

static ByteString com.google.protobuf.ByteString.copyFrom ( Iterable< ByteString byteStrings)
inlinestatic

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

ByteString

is not necessarily a unique object. If the list is empty, the returned object is the singleton empty

ByteString

. If the list has only one element, that

ByteString

will be returned without copying.

Parameters
byteStringsstrings to be concatenated
Returns
new
ByteString

◆ 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

ByteString

.

Parameters
textsource string
Returns
new
ByteString

◆ copyTo() [1/3]

void com.google.protobuf.ByteString.copyTo ( byte []  target,
int  offset 
)
inline

Copies bytes into a buffer at the given offset.

Parameters
targetbuffer to copy into
offsetin the target buffer
Exceptions
IndexOutOfBoundsExceptionif 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
targetbuffer to copy into
sourceOffsetoffset within these bytes
targetOffsetoffset within the target buffer
numberToCopynumber of bytes to copy
Exceptions
IndexOutOfBoundsExceptionif 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
targetByteBuffer to copy into.
Exceptions
java.nio.ReadOnlyBufferExceptionif the is read-only
java.nio.BufferOverflowExceptionif 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

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

numberToCopy > 0

.

◆ endsWith()

final boolean com.google.protobuf.ByteString.endsWith ( ByteString  suffix)
inline

Tests if this bytestring ends with the specified suffix. Similar to String#endsWith(String)

Parameters
suffixthe suffix.
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

ByteString

, 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

true

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()

final boolean com.google.protobuf.ByteString.isEmpty ( void  )
inline

Returns

true

if the size is

0

,

false

otherwise.

Returns
true if this is zero bytes long

◆ isValidUtf8()

abstract boolean com.google.protobuf.ByteString.isValidUtf8 ( )
abstract

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
whether the bytes in this
ByteString
are a well-formed UTF-8 byte sequence

◆ iterator()

final ByteIterator com.google.protobuf.ByteString.iterator ( )
inline

Return a ByteString.ByteIterator over the bytes in the ByteString. To avoid auto-boxing, you may get the iterator manually and call ByteIterator#nextByte().

Returns
the iterator

◆ newCodedInput()

abstract CodedInputStream com.google.protobuf.ByteString.newCodedInput ( )
abstract

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
stream based on wrapped data

◆ newInput()

abstract InputStream com.google.protobuf.ByteString.newInput ( )
abstract

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
an input stream that returns the bytes of this byte string.

◆ newOutput() [1/2]

static Output com.google.protobuf.ByteString.newOutput ( int  initialCapacity)
inlinestatic

Creates a new Output with the given initial capacity. Call Output#toByteString() to create the

ByteString

instance.

A ByteString.Output offers the same functionality as a ByteArrayOutputStream, except that it returns a ByteString rather than a

byte

array.

Parameters
initialCapacityestimate of number of bytes to be written
Returns
OutputStream
for building a
ByteString

◆ newOutput() [2/2]

static Output com.google.protobuf.ByteString.newOutput ( )
inlinestatic

Creates a new Output. Call Output#toByteString() to create the

ByteString

instance.

A ByteString.Output offers the same functionality as a ByteArrayOutputStream, except that it returns a ByteString rather than a

byte array

.

Returns
OutputStream
for building a
ByteString

◆ 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
hstarting hash value
offsetoffset into this value to start looking at data values
lengthnumber 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

ByteString

segments.

Parameters
stateeither
0
(if this is the initial decoding operation) or the value returned from a call to a partial decoding method for the previous bytes
offsetoffset of the first byte to check
lengthnumber of bytes to check
Returns
-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.

◆ 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

ByteString

, blocking if necessary until all bytes are read through to the end of the stream.

Performance notes: The returned

ByteString

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
streamToDrainThe source stream, which is read completely but not closed.
Returns
A new
ByteString
which is made up of chunks of various sizes, depending on the behavior of the underlying stream.
Exceptions
IOExceptionIOException 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

ByteString

, blocking if necessary until all bytes are read through to the end of the stream.

Performance notes: The returned

ByteString

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
streamToDrainThe source stream, which is read completely but not closed.
chunkSizeThe size of the chunks in which to read the stream.
Returns
A new
ByteString
which is made up of chunks of the given size.
Exceptions
IOExceptionIOException 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()

final boolean com.google.protobuf.ByteString.startsWith ( ByteString  prefix)
inline

Tests if this bytestring starts with the specified prefix. Similar to String#startsWith(String)

Parameters
prefixthe prefix.
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

beginIndex

, inclusive, to the end of the string.

Parameters
beginIndexstart at this index
Returns
substring sharing underlying data
Exceptions
IndexOutOfBoundsExceptionif
beginIndex < 0
or
beginIndex > size()
.

◆ substring() [2/2]

abstract ByteString com.google.protobuf.ByteString.substring ( int  beginIndex,
int  endIndex 
)
abstract

Return the substring from

beginIndex

, inclusive, to

endIndex

, exclusive.

Parameters
beginIndexstart at this index
endIndexthe last character is the one before this index
Returns
substring sharing underlying data
Exceptions
IndexOutOfBoundsExceptionif
beginIndex < 0
,
endIndex > size()
, or
beginIndex > endIndex
.

◆ toByteArray()

final byte [] com.google.protobuf.ByteString.toByteArray ( )
inline

Copies bytes to a

byte[]

.

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
charsetNameencode using this charset
Returns
new string
Exceptions
UnsupportedEncodingExceptionif 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
charsetencode 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
charsetencode 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
outthe output stream to which to write the data.
Exceptions
IOExceptionif an I/O error occurs.

Member Data Documentation

◆ EMPTY

final ByteString com.google.protobuf.ByteString.EMPTY = new LiteralByteString(Internal.EMPTY_BYTE_ARRAY)
static

Empty

ByteString

.


The documentation for this class was generated from the following file: