Interface PrimitiveArrays.Bytes
- Enclosing class:
PrimitiveArrays
bytes.
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.Cursorcursor()Returns aPrimitiveArrays.Cursor.default PrimitiveArrays.Cursorcursor(long position) Returns aPrimitiveArrays.Cursorwith the givenposition.default PrimitiveArrays.Cursorcursor(long position, long limit) static PrimitiveArrays.BytesfromByteArray(byte[] bytes) Returns aPrimitiveArrays.Byteswrappingbytes.static PrimitiveArrays.BytesfromByteBuffer(ByteBuffer buffer) Returns aPrimitiveArrays.Byteswrappingbuffer.byteget(long position) Returns thebyteat positionposition.longlength()Returns the length of this array.default doublereadLittleEndianDouble(long position) Returns a little-endian double read from this array atposition.default longreadUintWithLength(long position, int numBytes) Same asreadUintWithLength(Cursor, int), but does not require aPrimitiveArrays.Cursor.default longreadUintWithLength(PrimitiveArrays.Cursor cursor, int numBytes) Returns a unsigned integer consisting ofnumBytesbytes read from this array atcursor.positionin little-endian format as an unsigned 64-bit integer.default intreadVarint32(PrimitiveArrays.Cursor cursor) Same asreadVarint64(Cursor), but throws anIllegalArgumentExceptionif the read varint64 is greater thanInteger.MAX_VALUE.default longreadVarint64(PrimitiveArrays.Cursor cursor) Returns a unsigned integer consisting ofnumBytesbytes read from this array atcursor.positionin little-endian format as an unsigned 64-bit integer.default InputStreamReturns anInputStreamwrapping this array starting at the 0th byte.default InputStreamtoInputStream(long offset) Returns anInputStreamwrapping this array starting atoffset.default InputStreamtoInputStream(PrimitiveArrays.Cursor cursor) Returns anInputStreamwrapping this array starting atcursor.position.default voidwriteTo(OutputStream output) Writes this array tooutput.
-
Method Details
-
get
byte get(long position) Returns thebyteat positionposition.Throws an
IndexOutOfBoundsExceptionif the absolute get on the underlying implementation fails. -
length
long length()Returns the length of this array. -
cursor
-
cursor
Returns aPrimitiveArrays.Cursorwith the givenposition.The
limitof the returned cursor is thelength()of this array. -
cursor
Returns aPrimitiveArrays.Cursor.The
positionof the returned cursor is 0, and thelimitis thelength()of this array. -
fromByteBuffer
Returns aPrimitiveArrays.Byteswrappingbuffer.The returned array starts from index 0 of buffer, and its length is
buffer.limit(). -
fromByteArray
Returns aPrimitiveArrays.Byteswrappingbytes. -
toInputStream
Returns anInputStreamwrapping this array starting atoffset. -
toInputStream
Returns anInputStreamwrapping this array starting atcursor.position.cursor.positionis incremented for each byte read from the returnedInputStream. -
toInputStream
Returns anInputStreamwrapping this array starting at the 0th byte. -
writeTo
Writes this array tooutput.- Throws:
IOException
-
readVarint64
Returns a unsigned integer consisting ofnumBytesbytes read from this array atcursor.positionin little-endian format as an unsigned 64-bit integer.cursor.positionis updated to the index of the first byte following the varint64. -
readVarint32
Same asreadVarint64(Cursor), but throws anIllegalArgumentExceptionif the read varint64 is greater thanInteger.MAX_VALUE. -
readUintWithLength
Returns a unsigned integer consisting ofnumBytesbytes read from this array atcursor.positionin little-endian format as an unsigned 64-bit integer.cursor.positionis 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.
-