public interface Buffer extends BytesInput<Buffer>, BufferInput<Buffer>, BytesOutput<Buffer>, BufferOutput<Buffer>, io.atomix.utils.concurrent.ReferenceCounted<Buffer>
The byte buffer provides a fluent interface for reading bytes from and writing bytes to some underlying storage
implementation. The Buffer type is agnostic about the specific underlying storage implementation, but different
buffer implementations may be designed for specific storage layers.
Aside from the underlying storage implementation, this buffer works very similarly to Java's ByteBuffer.
It intentionally exposes methods that can be easily understood by any developer with experience with ByteBuffer.
In order to support reading and writing from buffers, Buffer implementations maintain a series of pointers to
aid in navigating the buffer.
Most notable of these pointers is the position. When values are written to or read from the buffer, the
buffer increments its internal position according to the number of bytes read. This allows users to iterate
through the bytes in the buffer without maintaining external pointers.
try (Buffer buffer = DirectBuffer.allocate(1024)) {
buffer.writeInt(1);
buffer.flip();
assert buffer.readInt() == 1;
}
Buffers implement ReferenceCounted in order to keep track of the number of currently
held references to a given buffer. When a buffer is constructed, the buffer contains only 1 reference. This
reference can be released via the close() method which can be called automatically
by using a try-with-resources statement demonstrated above. Additional references to the buffer should be acquired via
ReferenceCounted.acquire() and released via
ReferenceCounted.release(). Once all references to a buffer have been released - including
the initial reference - the memory will be freed (for in-memory buffers) and writes will be automatically flushed to
disk (for persistent buffers).
| Modifier and Type | Method and Description |
|---|---|
default byte[] |
array()
Returns the underlying byte array.
|
Buffer |
asReadOnlyBuffer()
Returns a read-only view of the buffer.
|
Bytes |
bytes()
Returns the bytes underlying the buffer.
|
int |
capacity()
Returns the buffer's capacity.
|
Buffer |
capacity(int capacity)
Sets the buffer's capacity.
|
Buffer |
clear()
Clears the buffer.
|
void |
close()
Closes the buffer.
|
Buffer |
compact()
Compacts the buffer, moving bytes from the current position to the end of the buffer to the head of the buffer.
|
Buffer |
duplicate()
Returns a duplicate of the buffer.
|
Buffer |
flip()
Flips the buffer.
|
default boolean |
hasArray()
Returns whether the buffer has an array.
|
boolean |
hasRemaining()
Returns a boolean indicating whether the buffer has bytes remaining.
|
boolean |
isDirect()
Returns a boolean value indicating whether the buffer is a direct buffer.
|
boolean |
isFile()
Returns a boolean value indicating whether the buffer is backed by a file.
|
boolean |
isReadOnly()
Returns a boolean value indicating whether the buffer is a read-only buffer.
|
int |
limit()
Returns the buffer's read/write limit.
|
Buffer |
limit(int limit)
Sets the buffer's read/write limit.
|
Buffer |
mark()
Sets a mark at the current position.
|
int |
maxCapacity()
Returns the maximum allowed capacity for the buffer.
|
int |
offset()
Returns the buffer's starting offset within the underlying
Bytes. |
ByteOrder |
order()
Returns the byte order.
|
Buffer |
order(ByteOrder order)
Sets the byte order, returning a new swapped
Buffer instance. |
Buffer |
position(int position)
Sets the buffer's current read/write position.
|
Buffer |
read(Buffer buffer)
Reads bytes into the given buffer.
|
Buffer |
read(byte[] bytes)
Reads bytes into the given byte array.
|
Buffer |
read(byte[] bytes,
int offset,
int length)
Reads bytes into the given byte array starting at current position up to the given length.
|
Buffer |
read(Bytes bytes)
Reads bytes into the given byte array.
|
Buffer |
read(Bytes bytes,
int dstOffset,
int length)
Reads bytes into the given byte array starting at the current position.
|
Buffer |
read(int srcOffset,
byte[] bytes,
int dstOffset,
int length)
Reads bytes into the given byte array starting at the given offset up to the given length.
|
Buffer |
read(int srcOffset,
Bytes bytes,
int dstOffset,
int length)
Reads bytes into the given byte array starting at the given offset up to the given length.
|
boolean |
readBoolean()
Reads a 1 byte boolean from the buffer at the current position.
|
boolean |
readBoolean(int offset)
Reads a 1 byte boolean from the buffer at the given offset.
|
int |
readByte()
Reads a byte from the buffer at the current position.
|
int |
readByte(int offset)
Reads a byte from the buffer at the given offset.
|
char |
readChar()
Reads a 16-bit character from the buffer at the current position.
|
char |
readChar(int offset)
Reads a 16-bit character from the buffer at the given offset.
|
double |
readDouble()
Reads a double-precision 64-bit floating point number from the buffer at the current position.
|
double |
readDouble(int offset)
Reads a double-precision 64-bit floating point number from the buffer at the given offset.
|
float |
readFloat()
Reads a single-precision 32-bit floating point number from the buffer at the current position.
|
float |
readFloat(int offset)
Reads a single-precision 32-bit floating point number from the buffer at the given offset.
|
int |
readInt()
Reads a 32-bit signed integer from the buffer at the current position.
|
int |
readInt(int offset)
Reads a 32-bit signed integer from the buffer at the given offset.
|
long |
readLong()
Reads a 64-bit signed integer from the buffer at the current position.
|
long |
readLong(int offset)
Reads a 64-bit signed integer from the buffer at the given offset.
|
short |
readShort()
Reads a 16-bit signed integer from the buffer at the current position.
|
short |
readShort(int offset)
Reads a 16-bit signed integer from the buffer at the given offset.
|
int |
readUnsignedByte()
Reads an unsigned byte from the buffer at the current position.
|
int |
readUnsignedByte(int offset)
Reads an unsigned byte from the buffer at the given offset.
|
long |
readUnsignedInt()
Reads a 32-bit unsigned integer from the buffer at the current position.
|
long |
readUnsignedInt(int offset)
Reads a 32-bit unsigned integer from the buffer at the given offset.
|
int |
readUnsignedShort()
Reads a 16-bit unsigned integer from the buffer at the current position.
|
int |
readUnsignedShort(int offset)
Reads a 16-bit unsigned integer from the buffer at the given offset.
|
String |
readUTF8()
Reads a UTF-8 string from the buffer at the current position.
|
String |
readUTF8(int offset)
Reads a UTF-8 string from the buffer at the given offset.
|
int |
remaining()
Returns the number of bytes remaining in the buffer until the
limit() is reached. |
Buffer |
reset()
Resets the buffer's position to the previously-marked position.
|
Buffer |
rewind()
Rewinds the buffer.
|
Buffer |
skip(int length)
Advances the buffer's
position length bytes. |
Buffer |
slice()
Returns a view of this buffer starting at the current position.
|
Buffer |
slice(int length)
Returns a view of this buffer of the given length starting at the current position.
|
Buffer |
slice(int offset,
int length)
Returns a view of this buffer starting at the given offset with the given length.
|
Buffer |
write(Buffer buffer)
Writes a buffer to the buffer.
|
Buffer |
write(byte[] bytes)
Writes an array of bytes to the buffer.
|
Buffer |
write(byte[] bytes,
int offset,
int length)
Writes an array of bytes to the buffer.
|
Buffer |
write(Bytes bytes)
Writes an array of bytes to the buffer.
|
Buffer |
write(Bytes bytes,
int offset,
int length)
Writes an array of bytes to the buffer.
|
Buffer |
write(int offset,
byte[] src,
int srcOffset,
int length)
Writes an array of bytes to the buffer.
|
Buffer |
write(int offset,
Bytes src,
int srcOffset,
int length)
Writes an array of bytes to the buffer.
|
Buffer |
writeBoolean(boolean b)
Writes a 1 byte boolean to the buffer at the current position.
|
Buffer |
writeBoolean(int offset,
boolean b)
Writes a 1 byte boolean to the buffer at the given offset.
|
Buffer |
writeByte(int b)
Writes a byte to the buffer at the current position.
|
Buffer |
writeByte(int offset,
int b)
Writes a byte to the buffer at the given offset.
|
Buffer |
writeChar(char c)
Writes a 16-bit character to the buffer at the current position.
|
Buffer |
writeChar(int offset,
char c)
Writes a 16-bit character to the buffer at the given offset.
|
Buffer |
writeDouble(double d)
Writes a double-precision 64-bit floating point number to the buffer at the current position.
|
Buffer |
writeDouble(int offset,
double d)
Writes a double-precision 64-bit floating point number to the buffer at the given offset.
|
Buffer |
writeFloat(float f)
Writes a single-precision 32-bit floating point number to the buffer at the current position.
|
Buffer |
writeFloat(int offset,
float f)
Writes a single-precision 32-bit floating point number to the buffer at the given offset.
|
Buffer |
writeInt(int i)
Writes a 32-bit signed integer to the buffer at the current position.
|
Buffer |
writeInt(int offset,
int i)
Writes a 32-bit signed integer to the buffer at the given offset.
|
Buffer |
writeLong(int offset,
long l)
Writes a 64-bit signed integer to the buffer at the given offset.
|
Buffer |
writeLong(long l)
Writes a 64-bit signed integer to the buffer at the current position.
|
Buffer |
writeShort(int offset,
short s)
Writes a 16-bit signed integer to the buffer at the given offset.
|
Buffer |
writeShort(short s)
Writes a 16-bit signed integer to the buffer at the current position.
|
Buffer |
writeUnsignedByte(int b)
Writes an unsigned byte to the buffer at the current position.
|
Buffer |
writeUnsignedByte(int offset,
int b)
Writes an unsigned byte to the buffer at the given offset.
|
Buffer |
writeUnsignedInt(int offset,
long i)
Writes a 32-bit signed integer to the buffer at the given offset.
|
Buffer |
writeUnsignedInt(long i)
Writes a 32-bit signed integer to the buffer at the current position.
|
Buffer |
writeUnsignedShort(int s)
Writes a 16-bit signed integer to the buffer at the current position.
|
Buffer |
writeUnsignedShort(int offset,
int s)
Writes a 16-bit signed integer to the buffer at the given offset.
|
Buffer |
writeUTF8(int offset,
String s)
Writes a UTF-8 string to the buffer at the given offset.
|
Buffer |
writeUTF8(String s)
Writes a UTF-8 string to the buffer at the current position.
|
readMedium, readString, readString, readUnsignedMediumposition, readBytes, readMedium, readString, readString, readUnsignedMediumflush, writeMedium, writeString, writeString, writeUnsignedMedium, zero, zero, zeroflush, writeBytes, writeMedium, writeString, writeString, writeUnsignedMediumdefault boolean hasArray()
default byte[] array()
UnsupportedOperationException - if a heap array is not supportedByteOrder order()
For consistency with ByteBuffer, all buffer implementations are initially in ByteOrder.BIG_ENDIAN order.
Buffer order(ByteOrder order)
Buffer instance.
By default, all buffers are read and written in ByteOrder.BIG_ENDIAN order. This provides complete
consistency with ByteBuffer. To flip buffers to ByteOrder.LITTLE_ENDIAN order, this
buffer's Bytes instance is decorated by a SwappedBytes instance which will reverse
read and written bytes using, e.g. Integer.reverseBytes(int).
order - The byte order.boolean isDirect()
boolean isReadOnly()
boolean isFile()
Buffer asReadOnlyBuffer()
The returned buffer will share the underlying Bytes with which buffer, but the buffer's limit,
capacity, and position will be independent of this buffer.
int offset()
Bytes.
The offset is used to calculate the absolute position of the buffer's relative position
within the underlying Bytes.
int capacity()
The capacity represents the total amount of storage space allocated to the buffer by the underlying storage
implementation. As bytes are written to the buffer, the buffer's capacity may grow up to maxCapacity().
Buffer capacity(int capacity)
The given capacity must be greater than the current capacity and less than or equal to
maxCapacity(). When the capacity is changed, the underlying Bytes will be resized via
Bytes.resize(int).
capacity - The capacity to which to resize the buffer.IllegalArgumentException - If the given capacity is less than the current capacity
or greater than maxCapacity()int maxCapacity()
The maximum capacity is the limit up to which this buffer's capacity can be expanded.
While the capacity grows, the maximum capacity is fixed from the moment the buffer is created and cannot change.
Buffer position(int position)
The position is an internal cursor that tracks where to write/read bytes in the underlying storage implementation.
position - The position to set.IllegalArgumentException - If the given position is less than 0 or more than limit()int limit()
The limit dictates the highest position to which bytes can be read from or written to the buffer. If the limit is
not explicitly set then it will always equal the buffer's maxCapacity. Note that the
limit may be set by related methods such as flip()
Buffer limit(int limit)
The limit dictates the highest position to which bytes can be read from or written to the buffer. The limit must
be within the bounds of the buffer, i.e. greater than 0 and less than or equal to capacity()
limit - The limit to set.IllegalArgumentException - If the given limit is less than 0 or more than capacity()int remaining()
limit() is reached.
The bytes remaining is calculated by buffer.limit() - buffer.position(). If no limit is set on the buffer
then the maxCapacity will be used.
remaining in interface BufferInput<Buffer>boolean hasRemaining()
If remaining() is greater than 0 then this method will return true, otherwise
false
hasRemaining in interface BufferInput<Buffer>true if remaining() is
greater than 0, false otherwise.Buffer flip()
The limit is set to the current position and then the position is set to zero. If the mark is defined then it is discarded.
assert buffer.writeLong(1234).flip().readLong() == 1234;
Buffer mark()
The mark is a simple internal reference to the buffer's current position. Marks can be used to reset the buffer to a specific position after some operation.
buffer.mark();
buffer.writeInt(1).writeBoolean(true);
buffer.reset();
assert buffer.readInt() == 1;
Buffer reset()
Invoking this method neither changes nor discards the mark's value.
InvalidMarkException - If no mark is set.Buffer rewind()
Buffer skip(int length)
position length bytes.skip in interface BufferInput<Buffer>length - The number of bytes to advance this buffer's position.IndexOutOfBoundsException - If length is greater than remaining()Buffer clear()
The position is set to zero, the limit is set to the capacity, and the mark is discarded.
Buffer compact()
Buffer duplicate()
Bytes bytes()
The buffer is a wrapper around Bytes that handles writing sequences of bytes by tracking positions and
limits. This method returns the Bytes that this buffer wraps.
Buffer slice()
The returned buffer will contain the same underlying Bytes instance as this buffer, but its pointers will
be offset by the current position of this buffer at the time the slice is created. Calls to
rewind() and similar methods on the resulting Buffer will result in
the buffer's position being reset to the position of this buffer at the time the slice was created.
The returned buffer is reference counted separately from this buffer. Therefore, closing the returned buffer will
release the buffer back to the internal buffer poll and will not result in this buffer being closed. Users should
always call close() once finished using the buffer slice.
slice(int),
slice(int, int)Buffer slice(int length)
The returned buffer will contain the same underlying Bytes instance as this buffer, but its pointers will
be offset by the current position of this buffer at the time the slice is created. Calls to
rewind() and similar methods on the resulting Buffer will result in
the buffer's position being reset to the position of this buffer at the time the slice was created.
The returned buffer is reference counted separately from this buffer. Therefore, closing the returned buffer will
release the buffer back to the internal buffer poll and will not result in this buffer being closed. Users should
always call close() once finished using the buffer slice.
length - The length of the slice.slice(),
slice(int, int)Buffer slice(int offset, int length)
The returned buffer will contain the same underlying Bytes instance as this buffer, but its pointers will
be offset by the given offset and its length limited by the given length. Calls to
rewind() and similar methods on the resulting Buffer will result in
the buffer's position being reset to the given offset.
The returned buffer is reference counted separately from this buffer. Therefore, closing the returned buffer will
release the buffer back to the internal buffer poll and will not result in this buffer being closed. Users should
always call close() once finished using the buffer slice.
offset - The offset at which to begin the slice.length - The number of bytes in the slice.IndexOutOfBoundsException - If the given offset is not contained within the bounds of this bufferBufferUnderflowException - If the length of the remaining bytes in the buffer is less than lengthslice(),
slice(int)Buffer read(Buffer buffer)
Bytes will be read starting at the current buffer position until either limit() has been reached.
If remaining() is less than the remaining() of the given buffer, a
BufferUnderflowException will be thrown.
read in interface BufferInput<Buffer>buffer - The buffer into which to read bytes.BufferUnderflowException - If the given remaining() is greater than this buffer's
remaining()Buffer read(Bytes bytes)
Bytes will be read starting at the current buffer position until either the byte array length or the
limit() has been reached. If remaining()
is less than the length of the given byte array, a BufferUnderflowException will be
thrown.
read in interface BufferInput<Buffer>bytes - The byte array into which to read bytes.BufferUnderflowException - If the given byte array's length is greater than
remaining()read(Bytes, int, int),
read(int, Bytes, int, int)Buffer read(byte[] bytes)
Bytes will be read starting at the current buffer position until either the byte array length or the
limit() has been reached. If remaining()
is less than the length of the given byte array, a BufferUnderflowException will be
thrown.
read in interface BufferInput<Buffer>bytes - The byte array into which to read bytes.BufferUnderflowException - If the given byte array's length is greater than
remaining()read(byte[], int, int),
read(int, byte[], int, int)Buffer read(Bytes bytes, int dstOffset, int length)
Bytes will be read from the current position up to the given length. If the provided length is
greater than remaining() then a BufferUnderflowException will
be thrown. If the offset is out of bounds of the buffer then an IndexOutOfBoundsException
will be thrown.
read in interface BufferInput<Buffer>bytes - The byte array into which to read bytes.dstOffset - The offset at which to write bytes into the given bufferBufferUnderflowException - If length is greater than remaining()IndexOutOfBoundsException - If the given offset is out of the bounds of the buffer. Note that
bounds are determined by the buffer's limit() rather than capacity.read(Bytes),
read(int, Bytes, int, int)Buffer read(int srcOffset, Bytes bytes, int dstOffset, int length)
Bytes will be read from the given starting offset up to the given length. If the provided length is
greater than - srcOffset then a BufferUnderflowException will
be thrown. If the srcOffset is out of bounds of the buffer then an IndexOutOfBoundsException
will be thrown.
read in interface BytesInput<Buffer>srcOffset - The offset from which to start reading bytes.bytes - The byte array into which to read bytes.dstOffset - The offset at which to write bytes into the given bufferlength - The total number of bytes to read.BufferUnderflowException - If length is greater than remaining()IndexOutOfBoundsException - If the given offset is out of the bounds of the buffer. Note that
bounds are determined by the buffer's limit() rather than capacity.read(Bytes),
read(Bytes, int, int)Buffer read(byte[] bytes, int offset, int length)
Bytes will be read from the current position up to the given length. If the provided length is
greater than remaining() then a BufferUnderflowException will
be thrown. If the offset is out of bounds of the buffer then an IndexOutOfBoundsException
will be thrown.
read in interface BufferInput<Buffer>bytes - The byte array into which to read bytes.offset - The offset at which to write bytes into the given bufferBufferUnderflowException - If length is greater than remaining()IndexOutOfBoundsException - If the given offset is out of the bounds of the buffer. Note that
bounds are determined by the buffer's limit() rather than capacity.read(byte[]),
read(int, byte[], int, int)Buffer read(int srcOffset, byte[] bytes, int dstOffset, int length)
Bytes will be read from the given starting offset up to the given length. If the provided length is
greater than remaining() then a BufferUnderflowException will
be thrown. If the offset is out of bounds of the buffer then an IndexOutOfBoundsException
will be thrown.
read in interface BytesInput<Buffer>srcOffset - The offset from which to start reading bytes.bytes - The byte array into which to read bytes.dstOffset - The offset at which to write bytes into the given bufferlength - The total number of bytes to read.BufferUnderflowException - If length is greater than remaining()IndexOutOfBoundsException - If the given offset is out of the bounds of the buffer. Note that
bounds are determined by the buffer's limit() rather than capacity.read(byte[]),
read(byte[], int, int)int readByte()
When the byte is read from the buffer, the buffer's position will be advanced by Bytes.BYTE. If
there are no bytes remaining in the buffer then a BufferUnderflowException will be thrown.
readByte in interface BufferInput<Buffer>BufferUnderflowException - If remaining() is less than Bytes.BYTEreadByte(int)int readByte(int offset)
The byte will be read from the given offset. If the given index is out of the bounds of the buffer then a
IndexOutOfBoundsException will be thrown.
readByte in interface BytesInput<Buffer>offset - The offset at which to read the byte.IndexOutOfBoundsException - If the given offset is out of the bounds of the buffer. Note that
bounds are determined by the buffer's limit() rather than capacity.readByte()int readUnsignedByte()
When the byte is read from the buffer, the buffer's position will be advanced by Bytes.BYTE. If
there are no bytes remaining in the buffer then a BufferUnderflowException will be thrown.
readUnsignedByte in interface BufferInput<Buffer>BufferUnderflowException - If remaining() is less than Bytes.BYTEreadUnsignedByte(int)int readUnsignedByte(int offset)
The byte will be read from the given offset. If the given index is out of the bounds of the buffer then a
IndexOutOfBoundsException will be thrown.
readUnsignedByte in interface BytesInput<Buffer>offset - The offset at which to read the byte.IndexOutOfBoundsException - If the given offset is out of the bounds of the buffer. Note that
bounds are determined by the buffer's limit() rather than capacity.readUnsignedByte()char readChar()
When the character is read from the buffer, the buffer's position will be advanced by Bytes.CHARACTER.
If there are less than Bytes.CHARACTER bytes remaining in the buffer then a
BufferUnderflowException will be thrown.
readChar in interface BufferInput<Buffer>BufferUnderflowException - If remaining() is less than Bytes.CHARACTERreadChar(int)char readChar(int offset)
The character will be read from the given offset. If the given index is out of the bounds of the buffer then a
IndexOutOfBoundsException will be thrown.
readChar in interface BytesInput<Buffer>offset - The offset at which to read the character.IndexOutOfBoundsException - If the given offset is out of the bounds of the buffer. Note that
bounds are determined by the buffer's limit() rather than capacity.readChar()short readShort()
When the short is read from the buffer, the buffer's position will be advanced by Bytes.SHORT.
If there are less than Bytes.SHORT bytes remaining in the buffer then a
BufferUnderflowException will be thrown.
readShort in interface BufferInput<Buffer>BufferUnderflowException - If remaining() is less than Bytes.SHORTreadShort(int)short readShort(int offset)
The short will be read from the given offset. If the given index is out of the bounds of the buffer then a
IndexOutOfBoundsException will be thrown.
readShort in interface BytesInput<Buffer>offset - The offset at which to read the short.IndexOutOfBoundsException - If the given offset is out of the bounds of the buffer. Note that
bounds are determined by the buffer's limit() rather than capacity.readShort()int readUnsignedShort()
When the short is read from the buffer, the buffer's position will be advanced by Bytes.SHORT.
If there are less than Bytes.SHORT bytes remaining in the buffer then a
BufferUnderflowException will be thrown.
readUnsignedShort in interface BufferInput<Buffer>BufferUnderflowException - If remaining() is less than Bytes.SHORTreadUnsignedShort(int)int readUnsignedShort(int offset)
The short will be read from the given offset. If the given index is out of the bounds of the buffer then a
IndexOutOfBoundsException will be thrown.
readUnsignedShort in interface BytesInput<Buffer>offset - The offset at which to read the short.IndexOutOfBoundsException - If the given offset is out of the bounds of the buffer. Note that
bounds are determined by the buffer's limit() rather than capacity.readUnsignedShort()int readInt()
When the integer is read from the buffer, the buffer's position will be advanced by Bytes.INTEGER.
If there are less than Bytes.INTEGER bytes remaining in the buffer then a
BufferUnderflowException will be thrown.
readInt in interface BufferInput<Buffer>BufferUnderflowException - If remaining() is less than Bytes.INTEGERreadInt(int)int readInt(int offset)
The integer will be read from the given offset. If the given index is out of the bounds of the buffer then a
IndexOutOfBoundsException will be thrown.
readInt in interface BytesInput<Buffer>offset - The offset at which to read the integer.IndexOutOfBoundsException - If the given offset is out of the bounds of the buffer. Note that
bounds are determined by the buffer's limit() rather than capacity.readInt()long readUnsignedInt()
When the integer is read from the buffer, the buffer's position will be advanced by Bytes.INTEGER.
If there are less than Bytes.INTEGER bytes remaining in the buffer then a
BufferUnderflowException will be thrown.
readUnsignedInt in interface BufferInput<Buffer>BufferUnderflowException - If remaining() is less than Bytes.INTEGERreadUnsignedInt(int)long readUnsignedInt(int offset)
The integer will be read from the given offset. If the given index is out of the bounds of the buffer then a
IndexOutOfBoundsException will be thrown.
readUnsignedInt in interface BytesInput<Buffer>offset - The offset at which to read the integer.IndexOutOfBoundsException - If the given offset is out of the bounds of the buffer. Note that
bounds are determined by the buffer's limit() rather than capacity.readUnsignedInt()long readLong()
When the long is read from the buffer, the buffer's position will be advanced by Bytes.LONG.
If there are less than Bytes.LONG bytes remaining in the buffer then a
BufferUnderflowException will be thrown.
readLong in interface BufferInput<Buffer>BufferUnderflowException - If remaining() is less than Bytes.LONGreadLong(int)long readLong(int offset)
The long will be read from the given offset. If the given index is out of the bounds of the buffer then a
IndexOutOfBoundsException will be thrown.
readLong in interface BytesInput<Buffer>offset - The offset at which to read the long.IndexOutOfBoundsException - If the given offset is out of the bounds of the buffer. Note that
bounds are determined by the buffer's limit() rather than capacity.readLong()float readFloat()
When the float is read from the buffer, the buffer's position will be advanced by Bytes.FLOAT.
If there are less than Bytes.FLOAT bytes remaining in the buffer then a
BufferUnderflowException will be thrown.
readFloat in interface BufferInput<Buffer>BufferUnderflowException - If remaining() is less than Bytes.FLOATreadFloat(int)float readFloat(int offset)
The float will be read from the given offset. If the given index is out of the bounds of the buffer then a
IndexOutOfBoundsException will be thrown.
readFloat in interface BytesInput<Buffer>offset - The offset at which to read the float.IndexOutOfBoundsException - If the given offset is out of the bounds of the buffer. Note that
bounds are determined by the buffer's limit() rather than capacity.readFloat()double readDouble()
When the double is read from the buffer, the buffer's position will be advanced by Bytes.DOUBLE.
If there are less than Bytes.DOUBLE bytes remaining in the buffer then a
BufferUnderflowException will be thrown.
readDouble in interface BufferInput<Buffer>BufferUnderflowException - If remaining() is less than Bytes.DOUBLEreadDouble(int)double readDouble(int offset)
The double will be read from the given offset. If the given index is out of the bounds of the buffer then a
IndexOutOfBoundsException will be thrown.
readDouble in interface BytesInput<Buffer>offset - The offset at which to read the double.IndexOutOfBoundsException - If the given offset is out of the bounds of the buffer. Note that
bounds are determined by the buffer's limit() rather than capacity.readDouble()boolean readBoolean()
When the boolean is read from the buffer, the buffer's position will be advanced by 1.
If there are no bytes remaining in the buffer then a BufferUnderflowException will be thrown.
readBoolean in interface BufferInput<Buffer>BufferUnderflowException - If remaining() is less than 1readBoolean(int)boolean readBoolean(int offset)
The boolean will be read from the given offset. If the given index is out of the bounds of the buffer then a
IndexOutOfBoundsException will be thrown.
readBoolean in interface BytesInput<Buffer>offset - The offset at which to read the boolean.IndexOutOfBoundsException - If the given offset is out of the bounds of the buffer. Note that
bounds are determined by the buffer's limit() rather than capacity.readBoolean()String readUTF8()
When the string is read from the buffer, the buffer's position will be advanced by 2 bytes plus the byte
length of the string. If there are no bytes remaining in the buffer then a BufferUnderflowException
will be thrown.
readUTF8 in interface BufferInput<Buffer>BufferUnderflowException - If remaining() is less than 1readUTF8(int)String readUTF8(int offset)
The string will be read from the given offset. If the given index is out of the bounds of the buffer then a
IndexOutOfBoundsException will be thrown.
readUTF8 in interface BytesInput<Buffer>offset - The offset at which to read the boolean.IndexOutOfBoundsException - If the given offset is out of the bounds of the buffer. Note that
bounds are determined by the buffer's limit() rather than capacity.readUTF8()Buffer write(Buffer buffer)
When the buffer is written to the buffer, the buffer's position will be advanced by the number of bytes
in the provided buffer. If the provided remaining() exceeds remaining() then an
BufferOverflowException will be thrown.
write in interface BufferOutput<Buffer>buffer - The buffer to write.BufferOverflowException - If the given buffer's remaining() bytes exceeds this buffer's
remaining bytes.Buffer write(Bytes bytes)
When the bytes are written to the buffer, the buffer's position will be advanced by the number of bytes
in the provided byte array. If the number of bytes exceeds limit() then an
BufferOverflowException will be thrown.
write in interface BufferOutput<Buffer>bytes - The array of bytes to write.BufferOverflowException - If the number of bytes exceeds the buffer's remaining bytes.write(Bytes, int, int),
write(int, Bytes, int, int)Buffer write(byte[] bytes)
When the bytes are written to the buffer, the buffer's position will be advanced by the number of bytes
in the provided byte array. If the number of bytes exceeds limit() then an
BufferOverflowException will be thrown.
write in interface BufferOutput<Buffer>bytes - The array of bytes to write.BufferOverflowException - If the number of bytes exceeds the buffer's remaining bytes.write(byte[], int, int),
write(int, byte[], int, int)Buffer write(Bytes bytes, int offset, int length)
The bytes will be written starting at the current position up to the given length. If the length of the byte array
is larger than the provided length then only length bytes will be read from the array. If the
provided length is greater than the remaining bytes in this buffer then a BufferOverflowException
will be thrown.
write in interface BufferOutput<Buffer>bytes - The array of bytes to write.offset - The offset at which to start writing the bytes.length - The number of bytes from the provided byte array to write to the buffer.BufferOverflowException - If there are not enough bytes remaining in the buffer.IndexOutOfBoundsException - If the given offset is out of the bounds of the buffer.write(Bytes),
write(int, Bytes, int, int)Buffer write(int offset, Bytes src, int srcOffset, int length)
The bytes will be written starting at the given offset up to the given length. If the remaining bytes in the byte array
is larger than the provided length then only length bytes will be read from the array. If the
provided length is greater than limit() minus offset then a
BufferOverflowException will be thrown.
write in interface BytesOutput<Buffer>offset - The offset at which to start writing the bytes.src - The array of bytes to write.srcOffset - The offset at which to begin reading bytes from the source.length - The number of bytes from the provided byte array to write to the buffer.BufferOverflowException - If there are not enough bytes remaining in the buffer.IndexOutOfBoundsException - If the given offset is out of the bounds of the buffer.write(Bytes),
write(Bytes, int, int)Buffer write(byte[] bytes, int offset, int length)
The bytes will be written starting at the current position up to the given length. If the length of the byte array
is larger than the provided length then only length bytes will be read from the array. If the
provided length is greater than the remaining bytes in this buffer then a BufferOverflowException
will be thrown.
write in interface BufferOutput<Buffer>bytes - The array of bytes to write.offset - The offset at which to start writing the bytes.length - The number of bytes from the provided byte array to write to the buffer.BufferOverflowException - If there are not enough bytes remaining in the buffer.IndexOutOfBoundsException - If the given offset is out of the bounds of the buffer.write(byte[]),
write(int, byte[], int, int)Buffer write(int offset, byte[] src, int srcOffset, int length)
The bytes will be written starting at the given offset up to the given length. If the remaining bytes in the byte array
is larger than the provided length then only length bytes will be read from the array. If the
provided length is greater than limit() minus offset then a
BufferOverflowException will be thrown.
write in interface BytesOutput<Buffer>offset - The offset at which to start writing the bytes.src - The array of bytes to write.srcOffset - The offset at which to begin reading bytes from the source.length - The number of bytes from the provided byte array to write to the buffer.BufferOverflowException - If there are not enough bytes remaining in the buffer.IndexOutOfBoundsException - If the given offset is out of the bounds of the buffer.write(byte[]),
write(byte[], int, int)Buffer writeByte(int b)
When the byte is written to the buffer, the buffer's position will be advanced by Bytes.BYTE. If
there are no bytes remaining in the buffer then a BufferOverflowException will be thrown.
writeByte in interface BufferOutput<Buffer>b - The byte to write.BufferOverflowException - If there are no bytes remaining in the buffer.writeByte(int, int)Buffer writeByte(int offset, int b)
The byte will be written at the given offset. If there are no bytes remaining in the buffer then a
BufferOverflowException will be thrown.
writeByte in interface BytesOutput<Buffer>offset - The offset at which to write the byte.b - The byte to write.BufferOverflowException - If there are not enough bytes remaining in the buffer.IndexOutOfBoundsException - If the given offset is out of the bounds of the buffer. Note that
bounds are determined by the buffer's limit() rather than capacity.writeByte(int)Buffer writeUnsignedByte(int b)
When the byte is written to the buffer, the buffer's position will be advanced by Bytes.BYTE. If
there are no bytes remaining in the buffer then a BufferOverflowException will be thrown.
writeUnsignedByte in interface BufferOutput<Buffer>b - The byte to write.BufferOverflowException - If there are no bytes remaining in the buffer.writeUnsignedByte(int, int)Buffer writeUnsignedByte(int offset, int b)
The byte will be written at the given offset. If there are no bytes remaining in the buffer then a
BufferOverflowException will be thrown.
writeUnsignedByte in interface BytesOutput<Buffer>offset - The offset at which to write the byte.b - The byte to write.BufferOverflowException - If there are not enough bytes remaining in the buffer.IndexOutOfBoundsException - If the given offset is out of the bounds of the buffer. Note that
bounds are determined by the buffer's limit() rather than capacity.writeUnsignedByte(int)Buffer writeChar(char c)
When the character is written to the buffer, the buffer's position will be advanced by
Bytes.CHARACTER. If less than 2 bytes are remaining in the buffer then a
BufferOverflowException will be thrown.
writeChar in interface BufferOutput<Buffer>c - The character to write.BufferOverflowException - If remaining() is less than Bytes.CHARACTER.writeChar(int, char)Buffer writeChar(int offset, char c)
The character will be written at the given offset. If there are less than Bytes.CHARACTER bytes remaining
in the buffer then a BufferOverflowException will be thrown.
writeChar in interface BytesOutput<Buffer>offset - The offset at which to write the character.c - The character to write.BufferOverflowException - If remaining() is less than Bytes.CHARACTER.IndexOutOfBoundsException - If the given offset is out of the bounds of the buffer. Note that
bounds are determined by the buffer's limit() rather than capacity.writeChar(char)Buffer writeShort(short s)
When the short is written to the buffer, the buffer's position will be advanced by Bytes.SHORT. If
less than Bytes.SHORT bytes are remaining in the buffer then a BufferOverflowException
will be thrown.
writeShort in interface BufferOutput<Buffer>s - The short to write.BufferOverflowException - If remaining() is less than Bytes.SHORT.writeShort(int, short)Buffer writeShort(int offset, short s)
The short will be written at the given offset. If there are less than Bytes.SHORT bytes remaining in the buffer
then a BufferOverflowException will be thrown.
writeShort in interface BytesOutput<Buffer>offset - The offset at which to write the short.s - The short to write.BufferOverflowException - If remaining() is less than Bytes.SHORT.IndexOutOfBoundsException - If the given offset is out of the bounds of the buffer. Note that
bounds are determined by the buffer's limit() rather than capacity.writeShort(short)Buffer writeUnsignedShort(int s)
When the short is written to the buffer, the buffer's position will be advanced by Bytes.SHORT. If
less than Bytes.SHORT bytes are remaining in the buffer then a BufferOverflowException
will be thrown.
writeUnsignedShort in interface BufferOutput<Buffer>s - The short to write.BufferOverflowException - If remaining() is less than Bytes.SHORT.writeUnsignedShort(int, int)Buffer writeUnsignedShort(int offset, int s)
The short will be written at the given offset. If there are less than Bytes.SHORT bytes remaining in the buffer
then a BufferOverflowException will be thrown.
writeUnsignedShort in interface BytesOutput<Buffer>offset - The offset at which to write the short.s - The short to write.BufferOverflowException - If remaining() is less than Bytes.SHORT.IndexOutOfBoundsException - If the given offset is out of the bounds of the buffer. Note that
bounds are determined by the buffer's limit() rather than capacity.writeUnsignedShort(int)Buffer writeInt(int i)
When the integer is written to the buffer, the buffer's position will be advanced by Bytes.INTEGER.
If less than Bytes.INTEGER bytes are remaining in the buffer then a BufferOverflowException
will be thrown.
writeInt in interface BufferOutput<Buffer>i - The integer to write.BufferOverflowException - If remaining() is less than Bytes.INTEGER.writeInt(int, int)Buffer writeInt(int offset, int i)
The integer will be written at the given offset. If there are less than Bytes.INTEGER bytes remaining
in the buffer then a BufferOverflowException will be thrown.
writeInt in interface BytesOutput<Buffer>offset - The offset at which to write the integer.i - The integer to write.BufferOverflowException - If remaining() is less than Bytes.INTEGER.IndexOutOfBoundsException - If the given offset is out of the bounds of the buffer. Note that
bounds are determined by the buffer's limit() rather than capacity.writeInt(int)Buffer writeUnsignedInt(long i)
When the integer is written to the buffer, the buffer's position will be advanced by Bytes.INTEGER.
If less than Bytes.INTEGER bytes are remaining in the buffer then a BufferOverflowException
will be thrown.
writeUnsignedInt in interface BufferOutput<Buffer>i - The integer to write.BufferOverflowException - If remaining() is less than Bytes.INTEGER.writeUnsignedInt(int, long)Buffer writeUnsignedInt(int offset, long i)
The integer will be written at the given offset. If there are less than Bytes.INTEGER bytes remaining
in the buffer then a BufferOverflowException will be thrown.
writeUnsignedInt in interface BytesOutput<Buffer>offset - The offset at which to write the integer.i - The integer to write.BufferOverflowException - If remaining() is less than Bytes.INTEGER.IndexOutOfBoundsException - If the given offset is out of the bounds of the buffer. Note that
bounds are determined by the buffer's limit() rather than capacity.writeUnsignedInt(long)Buffer writeLong(long l)
When the long is written to the buffer, the buffer's position will be advanced by Bytes.LONG.
If less than Bytes.LONG bytes are remaining in the buffer then a BufferOverflowException
will be thrown.
writeLong in interface BufferOutput<Buffer>l - The long to write.BufferOverflowException - If remaining() is less than Bytes.LONG.writeLong(int, long)Buffer writeLong(int offset, long l)
The long will be written at the given offset. If there are less than Bytes.LONG bytes remaining
in the buffer then a BufferOverflowException will be thrown.
writeLong in interface BytesOutput<Buffer>offset - The offset at which to write the long.l - The long to write.BufferOverflowException - If remaining() is less than Bytes.LONG.IndexOutOfBoundsException - If the given offset is out of the bounds of the buffer. Note that
bounds are determined by the buffer's limit() rather than capacity.writeLong(long)Buffer writeFloat(float f)
When the float is written to the buffer, the buffer's position will be advanced by Bytes.FLOAT.
If less than Bytes.FLOAT bytes are remaining in the buffer then a BufferOverflowException
will be thrown.
writeFloat in interface BufferOutput<Buffer>f - The float to write.BufferOverflowException - If remaining() is less than Bytes.FLOAT.writeFloat(int, float)Buffer writeFloat(int offset, float f)
The float will be written at the given offset. If there are less than Bytes.FLOAT bytes remaining
in the buffer then a BufferOverflowException will be thrown.
writeFloat in interface BytesOutput<Buffer>offset - The offset at which to write the float.f - The float to write.BufferOverflowException - If remaining() is less than Bytes.FLOAT.IndexOutOfBoundsException - If the given offset is out of the bounds of the buffer. Note that
bounds are determined by the buffer's limit() rather than capacity.writeFloat(float)Buffer writeDouble(double d)
When the double is written to the buffer, the buffer's position will be advanced by Bytes.DOUBLE.
If less than Bytes.DOUBLE bytes are remaining in the buffer then a BufferOverflowException
will be thrown.
writeDouble in interface BufferOutput<Buffer>d - The double to write.BufferOverflowException - If remaining() is less than Bytes.DOUBLE.writeDouble(int, double)Buffer writeDouble(int offset, double d)
The double will be written at the given offset. If there are less than Bytes.DOUBLE bytes remaining
in the buffer then a BufferOverflowException will be thrown.
writeDouble in interface BytesOutput<Buffer>offset - The offset at which to write the double.d - The double to write.BufferOverflowException - If remaining() is less than Bytes.DOUBLE.IndexOutOfBoundsException - If the given offset is out of the bounds of the buffer. Note that
bounds are determined by the buffer's limit() rather than capacity.writeDouble(double)Buffer writeBoolean(boolean b)
When the boolean is written to the buffer, the buffer's position will be advanced by 1.
If there are no bytes remaining in the buffer then a BufferOverflowException
will be thrown.
writeBoolean in interface BufferOutput<Buffer>b - The boolean to write.BufferOverflowException - If the number of bytes exceeds the buffer's remaining bytes.writeBoolean(int, boolean)Buffer writeBoolean(int offset, boolean b)
The boolean will be written as a single byte at the given offset. If there are no bytes remaining in the buffer
then a BufferOverflowException will be thrown.
writeBoolean in interface BytesOutput<Buffer>offset - The offset at which to write the boolean.b - The boolean to write.BufferOverflowException - If remaining() is less than 1.IndexOutOfBoundsException - If the given offset is out of the bounds of the buffer. Note that
bounds are determined by the buffer's limit() rather than capacity.writeBoolean(boolean)Buffer writeUTF8(String s)
The string will be written with a two-byte unsigned byte length followed by the UTF-8 bytes. If there are not enough
bytes remaining in the buffer then a BufferOverflowException will be thrown.
writeUTF8 in interface BufferOutput<Buffer>s - The string to write.BufferOverflowException - If the number of bytes exceeds the buffer's remaining bytes.writeUTF8(int, String)Buffer writeUTF8(int offset, String s)
The string will be written with a two-byte unsigned byte length followed by the UTF-8 bytes. If there are not enough
bytes remaining in the buffer then a BufferOverflowException will be thrown.
writeUTF8 in interface BytesOutput<Buffer>offset - The offset at which to write the string.s - The string to write.BufferOverflowException - If remaining() is less than 1.IndexOutOfBoundsException - If the given offset is out of the bounds of the buffer. Note that
bounds are determined by the buffer's limit() rather than capacity.writeUTF8(String)void close()
This method effectively acts as an alias to ReferenceCounted.release() and allows buffers to
be used as resources in try-with-resources statements. When the buffer is closed the internal reference counter
defined by ReferenceCounted will be decremented. However, if references to the
buffer still exist then those references will be allowed to continue to operate on the buffer until all references
have been released.
close in interface AutoCloseableclose in interface BufferInput<Buffer>close in interface BufferOutput<Buffer>close in interface io.atomix.utils.concurrent.ReferenceCounted<Buffer>Copyright © 2013–2017. All rights reserved.