Interface PrimitiveArrays.Bytes
-
- Enclosing class:
- PrimitiveArrays
public static interface PrimitiveArrays.Bytes
An array ofbyte
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
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default 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(java.nio.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 java.io.InputStream
toInputStream()
Returns anInputStream
wrapping this array starting at the 0th byte.default java.io.InputStream
toInputStream(long offset)
Returns anInputStream
wrapping this array starting atoffset
.default java.io.InputStream
toInputStream(PrimitiveArrays.Cursor cursor)
Returns anInputStream
wrapping this array starting atcursor.position
.default void
writeTo(java.io.OutputStream output)
Writes this array tooutput
.
-
-
-
Method Detail
-
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
default PrimitiveArrays.Cursor cursor(long position, long limit)
-
cursor
default PrimitiveArrays.Cursor cursor(long position)
Returns aPrimitiveArrays.Cursor
with the givenposition
.The
limit
of the returned cursor is thelength()
of this array.
-
cursor
default PrimitiveArrays.Cursor cursor()
Returns aPrimitiveArrays.Cursor
.The
position
of the returned cursor is 0, and thelimit
is thelength()
of this array.
-
fromByteBuffer
@GwtIncompatible("ByteBuffer") static PrimitiveArrays.Bytes fromByteBuffer(java.nio.ByteBuffer buffer)
Returns aPrimitiveArrays.Bytes
wrappingbuffer
.The returned array starts from index 0 of buffer, and its length is
buffer.limit()
.
-
fromByteArray
static PrimitiveArrays.Bytes fromByteArray(byte[] bytes)
Returns aPrimitiveArrays.Bytes
wrappingbytes
.
-
toInputStream
default java.io.InputStream toInputStream(long offset)
Returns anInputStream
wrapping this array starting atoffset
.
-
toInputStream
default java.io.InputStream toInputStream(PrimitiveArrays.Cursor cursor)
Returns anInputStream
wrapping this array starting atcursor.position
.cursor.position
is incremented for each byte read from the returnedInputStream
.
-
toInputStream
default java.io.InputStream toInputStream()
Returns anInputStream
wrapping this array starting at the 0th byte.
-
writeTo
default void writeTo(java.io.OutputStream output) throws java.io.IOException
Writes this array tooutput
.- Throws:
java.io.IOException
-
readVarint64
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.cursor.position
is updated to the index of the first byte following the varint64.
-
readVarint32
default int readVarint32(PrimitiveArrays.Cursor cursor)
Same asreadVarint64(Cursor)
, but throws anIllegalArgumentException
if the read varint64 is greater thanInteger.MAX_VALUE
.
-
readUintWithLength
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.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
.
-
-