Interface PrimitiveArrays.Bytes
- Enclosing class:
PrimitiveArrays
byte
s.
Implementations will be thread-safe if the underlying data is not mutated. Users should ensure the underlying data is not mutated in order to get predictable behaviour. Any buffering should be done internally.
Implementations may support arrays > 2GB in size like so:
new Bytes() {
byte get(long position) {
if (position < b1.length) {
return b1[Ints.checkedCast(position)];
}
return b2[Ints.checkedCast(position - b2.length)];
}
long length() { return b1.length + b2.length; }
}
-
Method Summary
Modifier and TypeMethodDescriptiondefault PrimitiveArrays.Cursor
cursor()
Returns aPrimitiveArrays.Cursor
.default PrimitiveArrays.Cursor
cursor
(long position) Returns aPrimitiveArrays.Cursor
with the givenposition
.default PrimitiveArrays.Cursor
cursor
(long position, long limit) static PrimitiveArrays.Bytes
fromByteArray
(byte[] bytes) Returns aPrimitiveArrays.Bytes
wrappingbytes
.static PrimitiveArrays.Bytes
fromByteBuffer
(ByteBuffer buffer) Returns aPrimitiveArrays.Bytes
wrappingbuffer
.byte
get
(long position) Returns thebyte
at positionposition
.long
length()
Returns the length of this array.default double
readLittleEndianDouble
(long position) Returns a little-endian double read from this array atposition
.default long
readUintWithLength
(long position, int numBytes) Same asreadUintWithLength(Cursor, int)
, but does not require aPrimitiveArrays.Cursor
.default long
readUintWithLength
(PrimitiveArrays.Cursor cursor, int numBytes) Returns a unsigned integer consisting ofnumBytes
bytes read from this array atcursor.position
in little-endian format as an unsigned 64-bit integer.default int
readVarint32
(PrimitiveArrays.Cursor cursor) Same asreadVarint64(Cursor)
, but throws anIllegalArgumentException
if the read varint64 is greater thanInteger.MAX_VALUE
.default long
readVarint64
(PrimitiveArrays.Cursor cursor) Returns a unsigned integer consisting ofnumBytes
bytes read from this array atcursor.position
in little-endian format as an unsigned 64-bit integer.default InputStream
Returns anInputStream
wrapping this array starting at the 0th byte.default InputStream
toInputStream
(long offset) Returns anInputStream
wrapping this array starting atoffset
.default InputStream
toInputStream
(PrimitiveArrays.Cursor cursor) Returns anInputStream
wrapping this array starting atcursor.position
.default void
writeTo
(OutputStream output) Writes this array tooutput
.
-
Method Details
-
get
byte get(long position) Returns thebyte
at positionposition
.Throws an
IndexOutOfBoundsException
if the absolute get on the underlying implementation fails. -
length
long length()Returns the length of this array. -
cursor
-
cursor
Returns aPrimitiveArrays.Cursor
with the givenposition
.The
limit
of the returned cursor is thelength()
of this array. -
cursor
Returns aPrimitiveArrays.Cursor
.The
position
of the returned cursor is 0, and thelimit
is thelength()
of this array. -
fromByteBuffer
Returns aPrimitiveArrays.Bytes
wrappingbuffer
.The returned array starts from index 0 of buffer, and its length is
buffer.limit()
. -
fromByteArray
Returns aPrimitiveArrays.Bytes
wrappingbytes
. -
toInputStream
Returns anInputStream
wrapping this array starting atoffset
. -
toInputStream
Returns anInputStream
wrapping this array starting atcursor.position
.cursor.position
is incremented for each byte read from the returnedInputStream
. -
toInputStream
Returns anInputStream
wrapping this array starting at the 0th byte. -
writeTo
Writes this array tooutput
.- Throws:
IOException
-
readVarint64
Returns a unsigned integer consisting ofnumBytes
bytes read from this array atcursor.position
in little-endian format as an unsigned 64-bit integer.cursor.position
is updated to the index of the first byte following the varint64. -
readVarint32
Same asreadVarint64(Cursor)
, but throws anIllegalArgumentException
if the read varint64 is greater thanInteger.MAX_VALUE
. -
readUintWithLength
Returns a unsigned integer consisting ofnumBytes
bytes read from this array atcursor.position
in little-endian format as an unsigned 64-bit integer.cursor.position
is updated to the index of the first byte following the uint.This method is not compatible with
readVarint64(Cursor)
. -
readUintWithLength
default long readUintWithLength(long position, int numBytes) Same asreadUintWithLength(Cursor, int)
, but does not require aPrimitiveArrays.Cursor
. -
readLittleEndianDouble
default double readLittleEndianDouble(long position) Returns a little-endian double read from this array atposition
.
-