Interface Buffer
- All Superinterfaces:
ClusterSerializable, Shareable
A buffer is a sequence of zero or more bytes that can read from or written to and which expands automatically as necessary to accommodate any bytes written to it. You can perhaps think of a buffer as smart byte array.
Please consult the documentation for more information on buffers.
- Author:
- Tim Fox
-
Method Summary
Modifier and TypeMethodDescriptionappendBuffer(Buffer buff) Appends the specifiedBufferto the end of this Buffer.appendBuffer(Buffer buff, int offset, int len) Appends the specifiedBufferstarting at theoffsetusinglento the end of this Buffer.appendByte(byte b) Appends the specifiedbyteto the end of the Buffer.appendBytes(byte[] bytes) Appends the specifiedbyte[]to the end of the Buffer.appendBytes(byte[] bytes, int offset, int len) Appends the specified number of bytes frombyte[]to the end of the Buffer, starting at the given offset.appendDouble(double d) Appends the specifieddoubleto the end of the Buffer.appendDoubleLE(double d) Appends the specified unsigneddoubleto the end of the Buffer in the Little Endian Byte Order.The buffer will expand as necessary to accommodate any bytes written.appendFloat(float f) Appends the specifiedfloatto the end of the Buffer.appendFloatLE(float f) Appends the specified unsignedfloatto the end of the Buffer in the Little Endian Byte Order.The buffer will expand as necessary to accommodate any bytes written.appendInt(int i) Appends the specifiedintto the end of the Buffer.appendIntLE(int i) Appends the specifiedintto the end of the Buffer in the Little Endian Byte Order.appendLong(long l) Appends the specifiedlongto the end of the Buffer.appendLongLE(long l) Appends the specifiedlongto the end of the Buffer in the Little Endian Byte Order.appendMedium(int i) Appends the specified 24bitintto the end of the Buffer.appendMediumLE(int i) Appends the specified 24bitintto the end of the Buffer in the Little Endian Byte Order.appendShort(short s) Appends the specifiedshortto the end of the Buffer.The buffer will expand as necessary to accommodate any bytes written.appendShortLE(short s) Appends the specifiedshortto the end of the Buffer in the Little Endian Byte Order.The buffer will expand as necessary to accommodate any bytes written.appendString(String str) Appends the specifiedString strto the end of the Buffer with UTF-8 encoding.appendString(String str, String enc) Appends the specifiedStringto the end of the Buffer with the encoding as specified byenc.appendUnsignedByte(short b) Appends the specified unsignedbyteto the end of the Buffer.appendUnsignedInt(long i) Appends the specified unsignedintto the end of the Buffer.appendUnsignedIntLE(long i) Appends the specified unsignedintto the end of the Buffer in the Little Endian Byte Order.appendUnsignedShort(int s) Appends the specified unsignedshortto the end of the Buffer.The buffer will expand as necessary to accommodate any bytes written.appendUnsignedShortLE(int s) Appends the specified unsignedshortto the end of the Buffer in the Little Endian Byte Order.The buffer will expand as necessary to accommodate any bytes written.static Bufferbuffer()Create a new, empty buffer.static Bufferbuffer(byte[] bytes) Create a new buffer from a byte[].static Bufferbuffer(int initialSizeHint) Create a new buffer given the initial size hint.static BufferCreate a new buffer from a string.static BufferCreate a new buffer from a string and using the specified encoding.copy()Returns a copy of the entire Buffer.static BufferCreate a buffer from the base 64 URL encodedvaluegetBuffer(int start, int end) Returns a copy of a sub-sequence the Buffer as aBufferstarting at positionstartand ending at positionend - 1bytegetByte(int pos) Returns thebyteat positionposin the Buffer.byte[]getBytes()Returns a copy of the entire Buffer as abyte[]getBytes(byte[] dst) Transfers the content of the Buffer into abyte[].getBytes(byte[] dst, int dstIndex) Transfers the content of the Buffer into abyte[]at the specific destination.byte[]getBytes(int start, int end) Returns a copy of a sub-sequence the Buffer as abyte[]starting at positionstartand ending at positionend - 1getBytes(int start, int end, byte[] dst) Transfers the content of the Buffer starting at positionstartand ending at positionend - 1into abyte[].getBytes(int start, int end, byte[] dst, int dstIndex) Transfers the content of the Buffer starting at positionstartand ending at positionend - 1into abyte[]at the specific destination.doublegetDouble(int pos) Returns thedoubleat positionposin the Buffer.doublegetDoubleLE(int pos) Gets a double at the specified absoluteindexin this buffer in Little Endian Byte Order.floatgetFloat(int pos) Returns thefloatat positionposin the Buffer.floatgetFloatLE(int pos) Gets a float at the specified absoluteindexin this buffer in Little Endian Byte Order.intgetInt(int pos) Returns theintat positionposin the Buffer.intgetIntLE(int pos) Gets a 32-bit integer at the specified absoluteindexin this buffer with Little Endian Byte Order.longgetLong(int pos) Returns thelongat positionposin the Buffer.longgetLongLE(int pos) Gets a 64-bit long integer at the specified absoluteindexin this buffer in Little Endian Byte Order.intgetMedium(int pos) Gets a 24-bit medium integer at the specified absoluteindexin this buffer.intgetMediumLE(int pos) Gets a 24-bit medium integer at the specified absoluteindexin this buffer in the Little Endian Byte Order.shortgetShort(int pos) Returns theshortat positionposin the Buffer.shortgetShortLE(int pos) Gets a 16-bit short integer at the specified absoluteindexin this buffer in Little Endian Byte Order.getString(int start, int end) Returns a copy of a sub-sequence the Buffer as aStringstarting at positionstartand ending at positionend - 1interpreted as a String in UTF-8 encodingReturns a copy of a sub-sequence the Buffer as aStringstarting at positionstartand ending at positionend - 1interpreted as a String in the specified encodingshortgetUnsignedByte(int pos) Returns the unsignedbyteat positionposin the Buffer, as ashort.longgetUnsignedInt(int pos) Returns the unsignedintat positionposin the Buffer, as along.longgetUnsignedIntLE(int pos) Returns the unsignedintat positionposin the Buffer, as alongin Little Endian Byte Order.intgetUnsignedMedium(int pos) Gets an unsigned 24-bit medium integer at the specified absoluteindexin this buffer.intgetUnsignedMediumLE(int pos) Gets an unsigned 24-bit medium integer at the specified absoluteindexin this buffer in Little Endian Byte Order.intgetUnsignedShort(int pos) Returns the unsignedshortat positionposin the Buffer, as anint.intgetUnsignedShortLE(int pos) Gets an unsigned 16-bit short integer at the specified absoluteindexin this buffer in Little Endian Byte Order.intlength()Returns the length of the buffer, measured in bytes.Sets the bytes at positionposin the Buffer to the bytes represented by theBuffer b.Sets the bytes at positionposin the Buffer to the bytes represented by theBuffer bon the givenoffsetandlen.setByte(int pos, byte b) Sets thebyteat positionposin the Buffer to the valueb.setBytes(int pos, byte[] b) Sets the bytes at positionposin the Buffer to the bytes represented by thebyte[] b.setBytes(int pos, byte[] b, int offset, int len) Sets the given number of bytes at positionposin the Buffer to the bytes represented by thebyte[] b.setBytes(int pos, ByteBuffer b) Sets the bytes at positionposin the Buffer to the bytes represented by theByteBuffer b.setDouble(int pos, double d) Sets thedoubleat positionposin the Buffer to the valued.setDoubleLE(int pos, double d) Sets thedoubleat positionposin the Buffer to the valuedin the Little Endian Byte Order.setFloat(int pos, float f) Sets thefloatat positionposin the Buffer to the valuef.setFloatLE(int pos, float f) Sets thefloatat positionposin the Buffer to the valuefin the Little Endian Byte Order.setInt(int pos, int i) Sets theintat positionposin the Buffer to the valuei.setIntLE(int pos, int i) Sets theintat positionposin the Buffer to the valueiin the Little Endian Byte Order.setLong(int pos, long l) Sets thelongat positionposin the Buffer to the valuel.setLongLE(int pos, long l) Sets thelongat positionposin the Buffer to the valuelin the Little Endian Byte Order.setMedium(int pos, int i) Sets the 24bitintat positionposin the Buffer to the valuei.setMediumLE(int pos, int i) Sets the 24bitintat positionposin the Buffer to the valuei. in the Little Endian Byte OrdersetShort(int pos, short s) Sets theshortat positionposin the Buffer to the values.setShortLE(int pos, short s) Sets theshortat positionposin the Buffer to the valuesin the Little Endian Byte Order.Sets the bytes at positionposin the Buffer to the value ofstrencoded in UTF-8.Sets the bytes at positionposin the Buffer to the value ofstrencoded in encodingenc.setUnsignedByte(int pos, short b) Sets the unsignedbyteat positionposin the Buffer to the valueb.setUnsignedInt(int pos, long i) Sets the unsignedintat positionposin the Buffer to the valuei.setUnsignedIntLE(int pos, long i) Sets the unsignedintat positionposin the Buffer to the valueiin the Little Endian Byte Order.setUnsignedShort(int pos, int s) Sets the unsignedshortat positionposin the Buffer to the values.setUnsignedShortLE(int pos, int s) Sets the unsignedshortat positionposin the Buffer to the valuesin the Little Endian Byte Order.slice()Returns a slice of this buffer.slice(int start, int end) Returns a slice of this buffer.default StringtoJson()Encode the buffer bytes to their base 64 URL encoded representation.Returns aJsonArrayrepresentation of this buffer's content.Returns aJsonObjectrepresentation of this buffer's content.default ObjectReturns a Json value representation of this buffer's content.toString()Returns aStringrepresentation of the Buffer with theUTF-8encodingReturns aStringrepresentation of the Buffer with the encoding specified byencReturns aStringrepresentation of the Buffer with the encoding specified byencMethods inherited from interface ClusterSerializable
readFromBuffer, writeToBuffer
-
Method Details
-
fromJson
-
buffer
-
buffer
Create a new buffer given the initial size hint.If you know the buffer will require a certain size, providing the hint can prevent unnecessary re-allocations as the buffer is written to and resized.
- Parameters:
initialSizeHint- the hint, in bytes- Returns:
- the buffer
-
buffer
-
buffer
-
buffer
Create a new buffer from a byte[]. The byte[] will be copied to form the buffer.- Parameters:
bytes- the byte array- Returns:
- the buffer
-
toString
-
toString
-
toString
-
toJsonObject
JsonObject toJsonObject()Returns aJsonObjectrepresentation of this buffer's content. -
toJsonArray
-
toJsonValue
Returns a Json value representation of this buffer's content.- Returns:
- a Json value which can be a
JsonArray,JsonObject,String, ... if the buffer contains an array, object, string, ...etc
-
toJson
Encode the buffer bytes to their base 64 URL encoded representation. -
getByte
byte getByte(int pos) Returns thebyteat positionposin the Buffer.- Throws:
IndexOutOfBoundsException- if the specifiedposis less than0orpos + 1is greater than the length of the Buffer.
-
getUnsignedByte
short getUnsignedByte(int pos) Returns the unsignedbyteat positionposin the Buffer, as ashort.- Throws:
IndexOutOfBoundsException- if the specifiedposis less than0orpos + 1is greater than the length of the Buffer.
-
getInt
int getInt(int pos) Returns theintat positionposin the Buffer.- Throws:
IndexOutOfBoundsException- if the specifiedposis less than0orpos + 4is greater than the length of the Buffer.
-
getIntLE
int getIntLE(int pos) Gets a 32-bit integer at the specified absoluteindexin this buffer with Little Endian Byte Order.- Throws:
IndexOutOfBoundsException- if the specifiedindexis less than0orindex + 4is greater thanthis.capacity
-
getUnsignedInt
long getUnsignedInt(int pos) Returns the unsignedintat positionposin the Buffer, as along.- Throws:
IndexOutOfBoundsException- if the specifiedposis less than0orpos + 4is greater than the length of the Buffer.
-
getUnsignedIntLE
long getUnsignedIntLE(int pos) Returns the unsignedintat positionposin the Buffer, as alongin Little Endian Byte Order.- Throws:
IndexOutOfBoundsException- if the specifiedposis less than0orpos + 4is greater than the length of the Buffer.
-
getLong
long getLong(int pos) Returns thelongat positionposin the Buffer.- Throws:
IndexOutOfBoundsException- if the specifiedposis less than0orpos + 8is greater than the length of the Buffer.
-
getLongLE
long getLongLE(int pos) Gets a 64-bit long integer at the specified absoluteindexin this buffer in Little Endian Byte Order.- Throws:
IndexOutOfBoundsException- if the specifiedindexis less than0orindex + 8is greater than the length of the Buffer.
-
getDouble
double getDouble(int pos) Returns thedoubleat positionposin the Buffer.- Throws:
IndexOutOfBoundsException- if the specifiedposis less than0orpos + 8is greater than the length of the Buffer.
-
getDoubleLE
double getDoubleLE(int pos) Gets a double at the specified absoluteindexin this buffer in Little Endian Byte Order.- Throws:
IndexOutOfBoundsException- if the specifiedposis less than0orpos + 8is greater than the length of the Buffer.
-
getFloat
float getFloat(int pos) Returns thefloatat positionposin the Buffer.- Throws:
IndexOutOfBoundsException- if the specifiedposis less than0orpos + 4is greater than the length of the Buffer.
-
getFloatLE
float getFloatLE(int pos) Gets a float at the specified absoluteindexin this buffer in Little Endian Byte Order.- Throws:
IndexOutOfBoundsException- if the specifiedposis less than0orpos + 4is greater than the length of the Buffer.
-
getShort
short getShort(int pos) Returns theshortat positionposin the Buffer.- Throws:
IndexOutOfBoundsException- if the specifiedposis less than0orpos + 2is greater than the length of the Buffer.
-
getShortLE
short getShortLE(int pos) Gets a 16-bit short integer at the specified absoluteindexin this buffer in Little Endian Byte Order.- Throws:
IndexOutOfBoundsException- if the specifiedindexis less than0orindex + 2is greater than the length of the Buffer.
-
getUnsignedShort
int getUnsignedShort(int pos) Returns the unsignedshortat positionposin the Buffer, as anint.- Throws:
IndexOutOfBoundsException- if the specifiedposis less than0orpos + 2is greater than the length of the Buffer.
-
getUnsignedShortLE
int getUnsignedShortLE(int pos) Gets an unsigned 16-bit short integer at the specified absoluteindexin this buffer in Little Endian Byte Order.- Throws:
IndexOutOfBoundsException- if the specifiedindexis less than0orindex + 2is greater than the length of the Buffer.
-
getMedium
int getMedium(int pos) Gets a 24-bit medium integer at the specified absoluteindexin this buffer.- Throws:
IndexOutOfBoundsException- if the specifiedindexis less than0orindex + 3is greater than the length of the Buffer.
-
getMediumLE
int getMediumLE(int pos) Gets a 24-bit medium integer at the specified absoluteindexin this buffer in the Little Endian Byte Order.- Throws:
IndexOutOfBoundsException- if the specifiedindexis less than0orindex + 3is greater than the length of the Buffer.
-
getUnsignedMedium
int getUnsignedMedium(int pos) Gets an unsigned 24-bit medium integer at the specified absoluteindexin this buffer.- Throws:
IndexOutOfBoundsException- if the specifiedindexis less than0orindex + 3is greater than the length of the Buffer.
-
getUnsignedMediumLE
int getUnsignedMediumLE(int pos) Gets an unsigned 24-bit medium integer at the specified absoluteindexin this buffer in Little Endian Byte Order.- Throws:
IndexOutOfBoundsException- if the specifiedindexis less than0orindex + 3is greater than the length of the Buffer.
-
getBytes
byte[] getBytes()Returns a copy of the entire Buffer as abyte[] -
getBytes
byte[] getBytes(int start, int end) Returns a copy of a sub-sequence the Buffer as abyte[]starting at positionstartand ending at positionend - 1 -
getBytes
Transfers the content of the Buffer into abyte[].- Parameters:
dst- the destination byte array- Throws:
IndexOutOfBoundsException- if the content of the Buffer cannot fit into the destination byte array
-
getBytes
Transfers the content of the Buffer into abyte[]at the specific destination.- Parameters:
dst- the destination byte array- Throws:
IndexOutOfBoundsException- if the content of the Buffer cannot fit into the destination byte array
-
getBytes
Transfers the content of the Buffer starting at positionstartand ending at positionend - 1into abyte[].- Parameters:
dst- the destination byte array- Throws:
IndexOutOfBoundsException- if the content of the Buffer cannot fit into the destination byte array
-
getBytes
Transfers the content of the Buffer starting at positionstartand ending at positionend - 1into abyte[]at the specific destination.- Parameters:
dst- the destination byte array- Throws:
IndexOutOfBoundsException- if the content of the Buffer cannot fit into the destination byte array
-
getBuffer
-
getString
-
getString
Returns a copy of a sub-sequence the Buffer as aStringstarting at positionstartand ending at positionend - 1interpreted as a String in UTF-8 encoding -
appendBuffer
-
appendBuffer
-
appendBytes
Appends the specifiedbyte[]to the end of the Buffer. The buffer will expand as necessary to accommodate any bytes written.Returns a reference to
thisso multiple operations can be appended together. -
appendBytes
Appends the specified number of bytes frombyte[]to the end of the Buffer, starting at the given offset. The buffer will expand as necessary to accommodate any bytes written.Returns a reference to
thisso multiple operations can be appended together. -
appendByte
Appends the specifiedbyteto the end of the Buffer. The buffer will expand as necessary to accommodate any bytes written.Returns a reference to
thisso multiple operations can be appended together. -
appendUnsignedByte
Appends the specified unsignedbyteto the end of the Buffer. The buffer will expand as necessary to accommodate any bytes written.Returns a reference to
thisso multiple operations can be appended together. -
appendInt
Appends the specifiedintto the end of the Buffer. The buffer will expand as necessary to accommodate any bytes written.Returns a reference to
thisso multiple operations can be appended together. -
appendIntLE
Appends the specifiedintto the end of the Buffer in the Little Endian Byte Order. The buffer will expand as necessary to accommodate any bytes written.Returns a reference to
thisso multiple operations can be appended together. -
appendUnsignedInt
Appends the specified unsignedintto the end of the Buffer. The buffer will expand as necessary to accommodate any bytes written.Returns a reference to
thisso multiple operations can be appended together. -
appendUnsignedIntLE
Appends the specified unsignedintto the end of the Buffer in the Little Endian Byte Order. The buffer will expand as necessary to accommodate any bytes written.Returns a reference to
thisso multiple operations can be appended together. -
appendMedium
Appends the specified 24bitintto the end of the Buffer. The buffer will expand as necessary to accommodate any bytes written.Returns a reference to
thisso multiple operations can be appended together. -
appendMediumLE
Appends the specified 24bitintto the end of the Buffer in the Little Endian Byte Order. The buffer will expand as necessary to accommodate any bytes written.Returns a reference to
thisso multiple operations can be appended together. -
appendLong
Appends the specifiedlongto the end of the Buffer. The buffer will expand as necessary to accommodate any bytes written.Returns a reference to
thisso multiple operations can be appended together. -
appendLongLE
Appends the specifiedlongto the end of the Buffer in the Little Endian Byte Order. The buffer will expand as necessary to accommodate any bytes written.Returns a reference to
thisso multiple operations can be appended together. -
appendShort
Appends the specifiedshortto the end of the Buffer.The buffer will expand as necessary to accommodate any bytes written.Returns a reference to
thisso multiple operations can be appended together. -
appendShortLE
Appends the specifiedshortto the end of the Buffer in the Little Endian Byte Order.The buffer will expand as necessary to accommodate any bytes written.Returns a reference to
thisso multiple operations can be appended together. -
appendUnsignedShort
Appends the specified unsignedshortto the end of the Buffer.The buffer will expand as necessary to accommodate any bytes written.Returns a reference to
thisso multiple operations can be appended together. -
appendUnsignedShortLE
Appends the specified unsignedshortto the end of the Buffer in the Little Endian Byte Order.The buffer will expand as necessary to accommodate any bytes written.Returns a reference to
thisso multiple operations can be appended together. -
appendFloat
Appends the specifiedfloatto the end of the Buffer. The buffer will expand as necessary to accommodate any bytes written.Returns a reference to
thisso multiple operations can be appended together. -
appendFloatLE
Appends the specified unsignedfloatto the end of the Buffer in the Little Endian Byte Order.The buffer will expand as necessary to accommodate any bytes written.Returns a reference to
thisso multiple operations can be appended together. -
appendDouble
Appends the specifieddoubleto the end of the Buffer. The buffer will expand as necessary to accommodate any bytes written.Returns a reference to
thisso multiple operations can be appended together. -
appendDoubleLE
Appends the specified unsigneddoubleto the end of the Buffer in the Little Endian Byte Order.The buffer will expand as necessary to accommodate any bytes written.Returns a reference to
thisso multiple operations can be appended together. -
appendString
-
appendString
-
setByte
Sets thebyteat positionposin the Buffer to the valueb.The buffer will expand as necessary to accommodate any value written.
-
setUnsignedByte
Sets the unsignedbyteat positionposin the Buffer to the valueb.The buffer will expand as necessary to accommodate any value written.
-
setInt
Sets theintat positionposin the Buffer to the valuei.The buffer will expand as necessary to accommodate any value written.
-
setIntLE
Sets theintat positionposin the Buffer to the valueiin the Little Endian Byte Order.The buffer will expand as necessary to accommodate any value written.
-
setUnsignedInt
Sets the unsignedintat positionposin the Buffer to the valuei.The buffer will expand as necessary to accommodate any value written.
-
setUnsignedIntLE
Sets the unsignedintat positionposin the Buffer to the valueiin the Little Endian Byte Order.The buffer will expand as necessary to accommodate any value written.
-
setMedium
Sets the 24bitintat positionposin the Buffer to the valuei.The buffer will expand as necessary to accommodate any value written.
-
setMediumLE
Sets the 24bitintat positionposin the Buffer to the valuei. in the Little Endian Byte OrderThe buffer will expand as necessary to accommodate any value written.
-
setLong
Sets thelongat positionposin the Buffer to the valuel.The buffer will expand as necessary to accommodate any value written.
-
setLongLE
Sets thelongat positionposin the Buffer to the valuelin the Little Endian Byte Order.The buffer will expand as necessary to accommodate any value written.
-
setDouble
Sets thedoubleat positionposin the Buffer to the valued.The buffer will expand as necessary to accommodate any value written.
-
setDoubleLE
Sets thedoubleat positionposin the Buffer to the valuedin the Little Endian Byte Order.The buffer will expand as necessary to accommodate any value written.
-
setFloat
Sets thefloatat positionposin the Buffer to the valuef.The buffer will expand as necessary to accommodate any value written.
-
setFloatLE
Sets thefloatat positionposin the Buffer to the valuefin the Little Endian Byte Order.The buffer will expand as necessary to accommodate any value written.
-
setShort
Sets theshortat positionposin the Buffer to the values.The buffer will expand as necessary to accommodate any value written.
-
setShortLE
Sets theshortat positionposin the Buffer to the valuesin the Little Endian Byte Order.The buffer will expand as necessary to accommodate any value written.
-
setUnsignedShort
Sets the unsignedshortat positionposin the Buffer to the values.The buffer will expand as necessary to accommodate any value written.
-
setUnsignedShortLE
Sets the unsignedshortat positionposin the Buffer to the valuesin the Little Endian Byte Order.The buffer will expand as necessary to accommodate any value written.
-
setBuffer
-
setBuffer
-
setBytes
Sets the bytes at positionposin the Buffer to the bytes represented by theByteBuffer b.The buffer will expand as necessary to accommodate any value written.
-
setBytes
Sets the bytes at positionposin the Buffer to the bytes represented by thebyte[] b.The buffer will expand as necessary to accommodate any value written.
-
setBytes
Sets the given number of bytes at positionposin the Buffer to the bytes represented by thebyte[] b. The buffer will expand as necessary to accommodate any value written. -
setString
-
setString
-
length
int length()Returns the length of the buffer, measured in bytes. All positions are indexed from zero. -
copy
-
slice
Buffer slice()Returns a slice of this buffer. Modifying the content of the returned buffer or this buffer affects each other's content while they maintain separate indexes and marks. -
slice
Returns a slice of this buffer. Modifying the content of the returned buffer or this buffer affects each other's content while they maintain separate indexes and marks.
-