private static final class ByteString.BoundedByteString extends ByteString.LiteralByteString
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.
ByteString.ByteIterator, ByteString.CodedBuilder, ByteString.LeafByteString, ByteString.Output
Modifier and Type | Field and Description |
---|---|
private int |
bytesLength |
private int |
bytesOffset |
private static long |
serialVersionUID |
bytes
CONCATENATE_BY_COPY_SIZE, EMPTY, MAX_READ_FROM_CHUNK_SIZE, MIN_READ_FROM_CHUNK_SIZE
Constructor and Description |
---|
BoundedByteString(byte[] bytes,
int offset,
int length)
Creates a
BoundedByteString backed by the sub-range of given array,
without copying. |
Modifier and Type | Method and Description |
---|---|
byte |
byteAt(int index)
Gets the byte at the given index.
|
protected void |
copyToInternal(byte[] target,
int sourceOffset,
int targetOffset,
int numberToCopy)
Internal (package private) implementation of
ByteString.copyTo(byte[],int,int,int) . |
protected int |
getOffsetIntoBytes()
Offset into
bytes[] to use, non-zero for substrings. |
private void |
readObject(java.io.ObjectInputStream in) |
int |
size()
Gets the number of bytes.
|
(package private) java.lang.Object |
writeReplace() |
asReadOnlyByteBuffer, asReadOnlyByteBufferList, copyTo, equals, equalsRange, isValidUtf8, newCodedInput, newInput, partialHash, partialIsValidUtf8, substring, toStringInternal, writeTo, writeTo, writeToInternal
getTreeDepth, isBalanced
checkIndex, checkRange, concat, copyFrom, copyFrom, copyFrom, copyFrom, copyFrom, copyFrom, copyFrom, copyFromUtf8, copyTo, copyTo, endsWith, hashCode, isEmpty, iterator, newCodedBuilder, newOutput, newOutput, peekCachedHashCode, readFrom, readFrom, readFrom, startsWith, substring, toByteArray, toString, toString, toString, toStringUtf8, wrap, wrap, wrap, writeTo
private final int bytesOffset
private final int bytesLength
private static final long serialVersionUID
BoundedByteString(byte[] bytes, int offset, int length)
BoundedByteString
backed by the sub-range of given array,
without copying.bytes
- array to wrapoffset
- index to first byte to use in byteslength
- number of bytes to use from bytesjava.lang.IllegalArgumentException
- if offset < 0
, length < 0
,
or if offset + length >
bytes.length
.public byte byteAt(int index)
ArrayIndexOutOfBoundsException
for backwards-compatibility reasons although it would more properly be
IndexOutOfBoundsException
.byteAt
in class ByteString.LiteralByteString
index
- index of bytejava.lang.ArrayIndexOutOfBoundsException
- index
is < 0 or >= sizepublic int size()
ByteString
size
in class ByteString.LiteralByteString
protected int getOffsetIntoBytes()
ByteString.LiteralByteString
bytes[]
to use, non-zero for substrings.getOffsetIntoBytes
in class ByteString.LiteralByteString
protected void copyToInternal(byte[] target, int sourceOffset, int targetOffset, int numberToCopy)
ByteString
ByteString.copyTo(byte[],int,int,int)
.
It assumes that all error checking has already been performed and that
numberToCopy > 0
.copyToInternal
in class ByteString.LiteralByteString
java.lang.Object writeReplace()
private void readObject(java.io.ObjectInputStream in) throws java.io.IOException
java.io.IOException