Package com.google.protobuf
Class ByteString.BoundedByteString
java.lang.Object
com.google.protobuf.ByteString
com.google.protobuf.ByteString.LeafByteString
com.google.protobuf.ByteString.LiteralByteString
com.google.protobuf.ByteString.BoundedByteString
- All Implemented Interfaces:
Serializable,Iterable<Byte>
- Enclosing class:
- ByteString
This class is used to represent the substring of a
ByteString over a single byte array.
In terms of the public API of ByteString, you end up here by calling ByteString.copyFrom(byte[]) followed by ByteString.substring(int, int).
This class contains most of the overhead involved in creating a substring from a ByteString.LiteralByteString. The overhead involves some range-checking and two extra fields.
-
Nested Class Summary
Nested classes/interfaces inherited from class com.google.protobuf.ByteString
ByteString.AbstractByteIterator, ByteString.ByteIterator, ByteString.CodedBuilder, ByteString.LeafByteString, ByteString.Output -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final intprivate final intprivate static final longFields inherited from class com.google.protobuf.ByteString.LiteralByteString
bytesFields inherited from class com.google.protobuf.ByteString
CONCATENATE_BY_COPY_SIZE, EMPTY, MAX_READ_FROM_CHUNK_SIZE, MIN_READ_FROM_CHUNK_SIZE -
Constructor Summary
ConstructorsConstructorDescriptionBoundedByteString(byte[] bytes, int offset, int length) Creates aBoundedByteStringbacked by the sub-range of given array, without copying. -
Method Summary
Modifier and TypeMethodDescriptionbytebyteAt(int index) Gets the byte at the given index.protected voidcopyToInternal(byte[] target, int sourceOffset, int targetOffset, int numberToCopy) Internal (package private) implementation ofByteString.copyTo(byte[],int,int,int).protected intOffset intobytes[]to use, non-zero for substrings.(package private) byteinternalByteAt(int index) Gets the byte at the given index, assumes bounds checking has already been performed.private voidintsize()Gets the number of bytes.(package private) ObjectMethods inherited from class com.google.protobuf.ByteString.LiteralByteString
asReadOnlyByteBuffer, asReadOnlyByteBufferList, copyTo, equals, equalsRange, isValidUtf8, newCodedInput, newInput, partialHash, partialIsValidUtf8, substring, toStringInternal, writeTo, writeTo, writeToInternalMethods inherited from class com.google.protobuf.ByteString.LeafByteString
getTreeDepth, isBalanced, writeToReverseMethods inherited from class com.google.protobuf.ByteString
checkIndex, checkRange, concat, copyFrom, copyFrom, copyFrom, copyFrom, copyFrom, copyFrom, copyFrom, copyFromUtf8, copyTo, copyTo, empty, endsWith, fromHex, hashCode, isEmpty, iterator, newCodedBuilder, newOutput, newOutput, peekCachedHashCode, readFrom, readFrom, readFrom, startsWith, substring, toByteArray, toString, toString, toString, toStringUtf8, unsignedLexicographicalComparator, wrap, wrap, wrap, writeToMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
bytesOffset
private final int bytesOffset -
bytesLength
private final int bytesLength -
serialVersionUID
private static final long serialVersionUID- See Also:
-
-
Constructor Details
-
BoundedByteString
BoundedByteString(byte[] bytes, int offset, int length) Creates aBoundedByteStringbacked by the sub-range of given array, without copying.- Parameters:
bytes- array to wrapoffset- index to first byte to use in byteslength- number of bytes to use from bytes- Throws:
IllegalArgumentException- ifoffset < 0,length < 0, or ifoffset + length > bytes.length.
-
-
Method Details
-
byteAt
public byte byteAt(int index) Gets the byte at the given index. ThrowsArrayIndexOutOfBoundsExceptionfor backwards-compatibility reasons although it would more properly beIndexOutOfBoundsException.- Overrides:
byteAtin classByteString.LiteralByteString- Parameters:
index- index of byte- Returns:
- the value
- Throws:
ArrayIndexOutOfBoundsException-indexis < 0 or >= size
-
internalByteAt
byte internalByteAt(int index) Description copied from class:ByteStringGets the byte at the given index, assumes bounds checking has already been performed.- Overrides:
internalByteAtin classByteString.LiteralByteString- Parameters:
index- index of byte- Returns:
- the value
-
size
public int size()Description copied from class:ByteStringGets the number of bytes.- Overrides:
sizein classByteString.LiteralByteString- Returns:
- size in bytes
-
getOffsetIntoBytes
protected int getOffsetIntoBytes()Description copied from class:ByteString.LiteralByteStringOffset intobytes[]to use, non-zero for substrings.- Overrides:
getOffsetIntoBytesin classByteString.LiteralByteString- Returns:
- always 0 for this class
-
copyToInternal
protected void copyToInternal(byte[] target, int sourceOffset, int targetOffset, int numberToCopy) Description copied from class:ByteStringInternal (package private) implementation ofByteString.copyTo(byte[],int,int,int). It assumes that all error checking has already been performed and thatnumberToCopy > 0.- Overrides:
copyToInternalin classByteString.LiteralByteString
-
writeReplace
Object writeReplace() -
readObject
- Throws:
IOException
-