Class BufferStub
- java.lang.Object
-
- io.netty5.buffer.api.BufferStub
-
- All Implemented Interfaces:
Buffer
,BufferAccessor
,Resource<Buffer>
,AutoCloseable
public class BufferStub extends Object implements Buffer
-
-
Constructor Summary
Constructors Constructor Description BufferStub(Buffer delegate)
Create a new buffer stub that delegates all calls to the given instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
bytesBefore(byte needle)
Get the number of readable bytes, until the givenneedle
is found in this buffer.int
capacity()
The capacity of this buffer, that is, the maximum number of bytes it can contain.void
close()
Close the resource, making it inaccessible.Buffer
compact()
Discards the read bytes, and moves the buffer contents to the beginning of the buffer.Buffer
copy()
Returns a copy of this buffer's readable bytes.Buffer
copy(int offset, int length)
Returns a copy of the given region of this buffer.void
copyInto(int srcPos, byte[] dest, int destPos, int length)
Copies the given length of data from this buffer into the given destination array, beginning at the given source position in this buffer, and the given destination position in the destination array.void
copyInto(int srcPos, Buffer dest, int destPos, int length)
Copies the given length of data from this buffer into the given destination buffer, beginning at the given source position in this buffer, and the given destination position in the destination buffer.void
copyInto(int srcPos, ByteBuffer dest, int destPos, int length)
Copies the given length of data from this buffer into the given destination byte buffer, beginning at the given source position in this buffer, and the given destination position in the destination byte buffer.int
countComponents()
Get the number of "components" in this buffer.int
countReadableComponents()
Get the number of "components" in this buffer, that are readable.int
countWritableComponents()
Get the number of "components" in this buffer, that are writable.Buffer
ensureWritable(int size)
Ensures that this buffer has at least the given number of bytes of available space for writing.Buffer
ensureWritable(int size, int minimumGrowth, boolean allowCompaction)
Ensures that this buffer has at least the given number of bytes of available space for writing.boolean
equals(Object obj)
Buffer
fill(byte value)
Fills the buffer with the given byte value.<E extends Exception>
intforEachReadable(int initialIndex, ReadableComponentProcessor<E> processor)
Processes all readable components of this buffer, and return the number of components processed.<E extends Exception>
intforEachWritable(int initialIndex, WritableComponentProcessor<E> processor)
Process all writable components of this buffer, and return the number of components processed.byte
getByte(int roff)
Get the byte value at the given reader offset.char
getChar(int roff)
Get the char value at the given reader offset.double
getDouble(int roff)
Get the double value at the given reader offset.float
getFloat(int roff)
Get the float value at the given reader offset.int
getInt(int roff)
Get the int value at the given reader offset.long
getLong(int roff)
Get the long value at the given reader offset.int
getMedium(int roff)
Get the int value at the given reader offset.short
getShort(int roff)
Get the short value at the given reader offset.int
getUnsignedByte(int roff)
Get the unsigned byte value at the given reader offset.long
getUnsignedInt(int roff)
Get the unsigned int value at the given reader offset.int
getUnsignedMedium(int roff)
Get the unsigned int value at the given reader offset.int
getUnsignedShort(int roff)
Get the unsigned short value at the given reader offset.int
hashCode()
boolean
isAccessible()
Check if this object is accessible.boolean
isDirect()
Queries if this buffer is backed by native memory, or not.Buffer
makeReadOnly()
Makes this buffer read-only.ByteCursor
openCursor()
Opens a cursor to iterate the readable bytes of this buffer.ByteCursor
openCursor(int fromOffset, int length)
Opens a cursor to iterate the given number bytes of this buffer, starting at the given offset.ByteCursor
openReverseCursor()
Opens a cursor to iterate the readable bytes of this buffer, in reverse.ByteCursor
openReverseCursor(int fromOffset, int length)
Opens a cursor to iterate the given number bytes of this buffer, in reverse, starting at the given offset.int
readableBytes()
Returns the number of readable bytes which is equal to(writerOffset() - readerOffset())
.byte
readByte()
Read the byte value at the currentBuffer.readerOffset()
, and increases the reader offset byByte.BYTES
.char
readChar()
Read the char value at the currentBuffer.readerOffset()
, and increases the reader offset by 2.double
readDouble()
Read the double value at the currentBuffer.readerOffset()
, and increases the reader offset byDouble.BYTES
.int
readerOffset()
Get the current reader offset.Buffer
readerOffset(int offset)
Set the reader offset.float
readFloat()
Read the float value at the currentBuffer.readerOffset()
, and increases the reader offset byFloat.BYTES
.int
readInt()
Read the int value at the currentBuffer.readerOffset()
, and increases the reader offset byInteger.BYTES
.long
readLong()
Read the long value at the currentBuffer.readerOffset()
, and increases the reader offset byLong.BYTES
.int
readMedium()
Read the int value at the currentBuffer.readerOffset()
, and increases the reader offset by 3.boolean
readOnly()
Queries if this buffer is read-only or not.short
readShort()
Read the short value at the currentBuffer.readerOffset()
, and increases the reader offset byShort.BYTES
.int
readUnsignedByte()
Read the unsigned byte value at the currentBuffer.readerOffset()
, and increases the reader offset byByte.BYTES
.long
readUnsignedInt()
Read the unsigned int value at the currentBuffer.readerOffset()
, and increases the reader offset byInteger.BYTES
.int
readUnsignedMedium()
Read the unsigned int value at the currentBuffer.readerOffset()
, and increases the reader offset by 3.int
readUnsignedShort()
Read the unsigned short value at the currentBuffer.readerOffset()
, and increases the reader offset byShort.BYTES
.Buffer
resetOffsets()
Resets the read offset and the write offset on this buffer to zero, and return this buffer.Send<Buffer>
send()
Send this object instance to another Thread, transferring the ownership to the recipient.Buffer
setByte(int woff, byte value)
Set the given byte value at the given write offset.Buffer
setChar(int woff, char value)
Set the given char value at the given write offset.Buffer
setDouble(int woff, double value)
Set the given double value at the given write offset.Buffer
setFloat(int woff, float value)
Set the given float value at the given write offset.Buffer
setInt(int woff, int value)
Set the given int value at the given write offset.Buffer
setLong(int woff, long value)
Set the given long value at the given write offset.Buffer
setMedium(int woff, int value)
Set the given int value at the given write offset.Buffer
setShort(int woff, short value)
Set the given short value at the given write offset.Buffer
setUnsignedByte(int woff, int value)
Set the given unsigned byte value at the given write offset.Buffer
setUnsignedInt(int woff, long value)
Set the given unsigned int value at the given write offset.Buffer
setUnsignedMedium(int woff, int value)
Set the given unsigned int value at the given write offset.Buffer
setUnsignedShort(int woff, int value)
Set the given unsigned short value at the given write offset.void
skipReadable(int delta)
Set the reader offset toreaderOffset() + delta
.void
skipWritable(int delta)
Set the write offset towriterOffset() + delta
.Buffer
split()
Splits the buffer into two, at the write offset position.Buffer
split(int splitOffset)
Splits the buffer into two, at the givensplitOffset
.String
toString(Charset charset)
Decodes this buffer's readable bytes into a string with the specified Charset.Buffer
touch(Object hint)
Record the current access location for debugging purposes.int
transferFrom(ReadableByteChannel channel, int length)
Read from the given channel and write to this buffer.int
transferTo(WritableByteChannel channel, int length)
Read from this buffer and write to the given channel.int
writableBytes()
Returns the number of writable bytes which is equal to(capacity() - writerOffset())
.Buffer
writeByte(byte value)
Write the given byte value at the currentBuffer.writerOffset()
, and increase the writer offset byByte.BYTES
.Buffer
writeBytes(byte[] source)
Writes into this buffer, all the bytes from the given byte array.Buffer
writeBytes(Buffer source)
Writes into this buffer, all the readable bytes from the given buffer.Buffer
writeChar(char value)
Write the given char value at the currentBuffer.writerOffset()
, and increase the writer offset by 2.Buffer
writeDouble(double value)
Write the given double value at the currentBuffer.writerOffset()
, and increase the writer offset byDouble.BYTES
.Buffer
writeFloat(float value)
Write the given float value at the currentBuffer.writerOffset()
, and increase the writer offset byFloat.BYTES
.Buffer
writeInt(int value)
Write the given int value at the currentBuffer.writerOffset()
, and increase the writer offset byInteger.BYTES
.Buffer
writeLong(long value)
Write the given long value at the currentBuffer.writerOffset()
, and increase the writer offset byLong.BYTES
.Buffer
writeMedium(int value)
Write the given int value at the currentBuffer.writerOffset()
, and increase the writer offset by 3.int
writerOffset()
Get the current writer offset.Buffer
writerOffset(int offset)
Set the writer offset.Buffer
writeShort(short value)
Write the given short value at the currentBuffer.writerOffset()
, and increase the writer offset byShort.BYTES
.Buffer
writeUnsignedByte(int value)
Write the given unsigned byte value at the currentBuffer.writerOffset()
, and increase the writer offset byByte.BYTES
.Buffer
writeUnsignedInt(long value)
Write the given unsigned int value at the currentBuffer.writerOffset()
, and increase the writer offset byInteger.BYTES
.Buffer
writeUnsignedMedium(int value)
Write the given unsigned int value at the currentBuffer.writerOffset()
, and increase the writer offset by 3.Buffer
writeUnsignedShort(int value)
Write the given unsigned short value at the currentBuffer.writerOffset()
, and increase the writer offset byShort.BYTES
.-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface io.netty5.buffer.api.Buffer
readBytes, readCharSequence, readSplit, writeBytes, writeCharSequence, writeSplit
-
-
-
-
Field Detail
-
delegate
protected final Buffer delegate
-
-
Constructor Detail
-
BufferStub
public BufferStub(Buffer delegate)
Create a new buffer stub that delegates all calls to the given instance.- Parameters:
delegate
- The buffer instance to delegate all method calls to.
-
-
Method Detail
-
capacity
public int capacity()
Description copied from interface:Buffer
The capacity of this buffer, that is, the maximum number of bytes it can contain.
-
readerOffset
public int readerOffset()
Description copied from interface:Buffer
Get the current reader offset. The next read will happen from this byte offset into the buffer.- Specified by:
readerOffset
in interfaceBuffer
- Returns:
- The current reader offset.
-
skipReadable
public void skipReadable(int delta)
Description copied from interface:Buffer
Set the reader offset toreaderOffset() + delta
.- Specified by:
skipReadable
in interfaceBuffer
- Parameters:
delta
- to accumulate.
-
readerOffset
public Buffer readerOffset(int offset)
Description copied from interface:Buffer
Set the reader offset. Make the next read happen from the given offset into the buffer.- Specified by:
readerOffset
in interfaceBuffer
- Parameters:
offset
- The reader offset to set.- Returns:
- This Buffer.
-
writerOffset
public int writerOffset()
Description copied from interface:Buffer
Get the current writer offset. The next write will happen at this byte offset into the buffer.- Specified by:
writerOffset
in interfaceBuffer
- Returns:
- The current writer offset.
-
skipWritable
public void skipWritable(int delta)
Description copied from interface:Buffer
Set the write offset towriterOffset() + delta
.- Specified by:
skipWritable
in interfaceBuffer
- Parameters:
delta
- to accumulate.
-
writerOffset
public Buffer writerOffset(int offset)
Description copied from interface:Buffer
Set the writer offset. Make the next write happen at the given offset.- Specified by:
writerOffset
in interfaceBuffer
- Parameters:
offset
- The writer offset to set.- Returns:
- This Buffer.
-
readableBytes
public int readableBytes()
Description copied from interface:Buffer
Returns the number of readable bytes which is equal to(writerOffset() - readerOffset())
.- Specified by:
readableBytes
in interfaceBuffer
-
writableBytes
public int writableBytes()
Description copied from interface:Buffer
Returns the number of writable bytes which is equal to(capacity() - writerOffset())
.- Specified by:
writableBytes
in interfaceBuffer
-
fill
public Buffer fill(byte value)
Description copied from interface:Buffer
Fills the buffer with the given byte value. This method does not respect theBuffer.readerOffset()
orBuffer.writerOffset()
, but copies the full capacity of the buffer. TheBuffer.readerOffset()
andBuffer.writerOffset()
are not modified.
-
makeReadOnly
public Buffer makeReadOnly()
Description copied from interface:Buffer
Makes this buffer read-only. This is irreversible. This operation is also idempotent, so calling this method multiple times on the same buffer makes no difference.- Specified by:
makeReadOnly
in interfaceBuffer
- Returns:
- This buffer instance.
-
readOnly
public boolean readOnly()
Description copied from interface:Buffer
Queries if this buffer is read-only or not.
-
isDirect
public boolean isDirect()
Description copied from interface:Buffer
Queries if this buffer is backed by native memory, or not.
-
copyInto
public void copyInto(int srcPos, byte[] dest, int destPos, int length)
Description copied from interface:Buffer
Copies the given length of data from this buffer into the given destination array, beginning at the given source position in this buffer, and the given destination position in the destination array.This method does not read or modify the write offset or the read offset.
- Specified by:
copyInto
in interfaceBuffer
- Parameters:
srcPos
- The byte offset into this buffer from where the copying should start; the byte at this offset in this buffer will be copied to thedestPos
index in thedest
array.dest
- The destination byte array.destPos
- The index into thedest
array from where the copying should start.length
- The number of bytes to copy.
-
copyInto
public void copyInto(int srcPos, ByteBuffer dest, int destPos, int length)
Description copied from interface:Buffer
Copies the given length of data from this buffer into the given destination byte buffer, beginning at the given source position in this buffer, and the given destination position in the destination byte buffer.This method does not read or modify the write offset or the read offset, nor is the position of the destination buffer changed.
The position and limit of the destination byte buffer are also ignored, and do not influence
destPos
orlength
.- Specified by:
copyInto
in interfaceBuffer
- Parameters:
srcPos
- The byte offset into this buffer from where the copying should start; the byte at this offset in this buffer will be copied to thedestPos
index in thedest
array.dest
- The destination byte buffer.destPos
- The index into thedest
array from where the copying should start.length
- The number of bytes to copy.
-
copyInto
public void copyInto(int srcPos, Buffer dest, int destPos, int length)
Description copied from interface:Buffer
Copies the given length of data from this buffer into the given destination buffer, beginning at the given source position in this buffer, and the given destination position in the destination buffer.This method does not read or modify the write offset or the read offset on this buffer, nor on the destination buffer.
The read and write offsets of the destination buffer are also ignored, and do not influence
destPos
orlength
.- Specified by:
copyInto
in interfaceBuffer
- Parameters:
srcPos
- The byte offset into this buffer from where the copying should start; the byte at this offset in this buffer will be copied to thedestPos
index in thedest
array.dest
- The destination buffer.destPos
- The index into thedest
array from where the copying should start.length
- The number of bytes to copy.
-
transferTo
public int transferTo(WritableByteChannel channel, int length) throws IOException
Description copied from interface:Buffer
Read from this buffer and write to the given channel. The number of bytes actually written to the channel are returned. No more than the givenlength
of bytes, or the number of readable bytes, will be written to the channel, whichever is smaller. If the channel has a position, then it will be advanced by the number of bytes written. The reader-offset of this buffer will likewise be advanced by the number of bytes written.- Specified by:
transferTo
in interfaceBuffer
- Parameters:
channel
- The channel to write to.length
- The maximum number of bytes to write.- Returns:
- The actual number of bytes written, possibly zero.
- Throws:
IOException
- If the write-operation on the channel failed for some reason.
-
transferFrom
public int transferFrom(ReadableByteChannel channel, int length) throws IOException
Description copied from interface:Buffer
Read from the given channel and write to this buffer. The number of bytes actually read from the channel are returned, or -1 is returned if the channel has reached the end-of-stream. No more than the givenlength
of bytes, or the number of writable bytes, will be read from the channel, whichever is smaller. If the channel has a position, then it will be advanced by the number of bytes read. The writer-offset of this buffer will likewise be advanced by the number of bytes read.- Specified by:
transferFrom
in interfaceBuffer
- Parameters:
channel
- The channel to read from.length
- The maximum number of bytes to read.- Returns:
- The actual number of bytes read, possibly zero, or -1 if the end-of-stream has been reached.
- Throws:
IOException
- If the read-operation on the channel failed for some reason.
-
writeBytes
public Buffer writeBytes(Buffer source)
Description copied from interface:Buffer
Writes into this buffer, all the readable bytes from the given buffer. This updates the write offset of this buffer, and the reader offset of the given buffer.- Specified by:
writeBytes
in interfaceBuffer
- Parameters:
source
- The buffer to read from.- Returns:
- This buffer.
-
writeBytes
public Buffer writeBytes(byte[] source)
Description copied from interface:Buffer
Writes into this buffer, all the bytes from the given byte array. This updates the write offset of this buffer by the length of the array.- Specified by:
writeBytes
in interfaceBuffer
- Parameters:
source
- The byte array to read from.- Returns:
- This buffer.
-
resetOffsets
public Buffer resetOffsets()
Description copied from interface:Buffer
Resets the read offset and the write offset on this buffer to zero, and return this buffer.- Specified by:
resetOffsets
in interfaceBuffer
- Returns:
- This buffer instance.
-
bytesBefore
public int bytesBefore(byte needle)
Description copied from interface:Buffer
Get the number of readable bytes, until the givenneedle
is found in this buffer. If the needle is not found,-1
is returned.This method does not modify the reader-offset or the write-offset.
- Specified by:
bytesBefore
in interfaceBuffer
- Parameters:
needle
- The byte value to search for.- Returns:
- The offset, relative to the current
Buffer.readerOffset()
, of the found value, or-1
if none was found.
-
openCursor
public ByteCursor openCursor()
Description copied from interface:Buffer
Opens a cursor to iterate the readable bytes of this buffer. The reader offset and writer offset are not modified by the cursor.Care should be taken to ensure that the buffer's lifetime extends beyond the cursor and the iteration, and that the reader offset and writer offset are not modified while the iteration takes place. Otherwise, unpredictable behaviour might result.
- Specified by:
openCursor
in interfaceBuffer
- Returns:
- A
ByteCursor
for iterating the readable bytes of this buffer.
-
openCursor
public ByteCursor openCursor(int fromOffset, int length)
Description copied from interface:Buffer
Opens a cursor to iterate the given number bytes of this buffer, starting at the given offset. The reader offset and writer offset are not modified by the cursor.Care should be taken to ensure that the buffer's lifetime extends beyond the cursor and the iteration, and that the reader offset and writer offset are not modified while the iteration takes place. Otherwise, unpredictable behaviour might result.
- Specified by:
openCursor
in interfaceBuffer
- Parameters:
fromOffset
- The offset into the buffer where iteration should start. The first byte read from the iterator will be the byte at this offset.length
- The number of bytes to iterate.- Returns:
- A
ByteCursor
for the given stretch of bytes of this buffer.
-
openReverseCursor
public ByteCursor openReverseCursor()
Description copied from interface:Buffer
Opens a cursor to iterate the readable bytes of this buffer, in reverse. The reader offset and writer offset are not modified by the cursor.Care should be taken to ensure that the buffer's lifetime extends beyond the cursor and the iteration, and that the reader offset and writer offset are not modified while the iteration takes place. Otherwise, unpredictable behaviour might result.
- Specified by:
openReverseCursor
in interfaceBuffer
- Returns:
- A
ByteCursor
for the readable bytes of this buffer.
-
openReverseCursor
public ByteCursor openReverseCursor(int fromOffset, int length)
Description copied from interface:Buffer
Opens a cursor to iterate the given number bytes of this buffer, in reverse, starting at the given offset. The reader offset and writer offset are not modified by the cursor.Care should be taken to ensure that the buffer's lifetime extends beyond the cursor and the iteration, and that the reader offset and writer offset are not modified while the iteration takes place. Otherwise, unpredictable behaviour might result.
- Specified by:
openReverseCursor
in interfaceBuffer
- Parameters:
fromOffset
- The offset into the buffer where iteration should start. The first byte read from the iterator will be the byte at this offset.length
- The number of bytes to iterate.- Returns:
- A
ByteCursor
for the given stretch of bytes of this buffer.
-
ensureWritable
public Buffer ensureWritable(int size)
Description copied from interface:Buffer
Ensures that this buffer has at least the given number of bytes of available space for writing. If this buffer already has the necessary space, then this method returns immediately. If this buffer does not already have the necessary space, then it will be expanded using theBufferAllocator
the buffer was created with. This method is the same as callingBuffer.ensureWritable(int, int, boolean)
whereallowCompaction
isfalse
.- Specified by:
ensureWritable
in interfaceBuffer
- Parameters:
size
- The requested number of bytes of space that should be available for writing.- Returns:
- This buffer instance.
-
ensureWritable
public Buffer ensureWritable(int size, int minimumGrowth, boolean allowCompaction)
Description copied from interface:Buffer
Ensures that this buffer has at least the given number of bytes of available space for writing. If this buffer already has the necessary space, then this method returns immediately. If this buffer does not already have the necessary space, then space will be made available in one or all of the following available ways:-
If
allowCompaction
istrue
, and sum of the read and writable bytes would be enough to satisfy the request, and it (depending on the buffer implementation) seems faster and easier to compact the existing buffer rather than allocation a new buffer, then the requested bytes will be made available that way. The compaction will not necessarily work the same way as theBuffer.compact()
method, as the implementation may be able to make the requested bytes available with less effort than is strictly mandated by theBuffer.compact()
method. -
Regardless of the value of the
allowCompaction
, the implementation may make more space available by just allocating more or larger buffers. This allocation would use the sameBufferAllocator
that this buffer was created with. -
If
allowCompaction
istrue
, then the implementation may choose to do a combination of compaction and allocation.
- Specified by:
ensureWritable
in interfaceBuffer
- Parameters:
size
- The requested number of bytes of space that should be available for writing.minimumGrowth
- The minimum number of bytes to grow by. If it is determined that memory should be allocated and copied, make sure that the new memory allocation is bigger than the old one by at least this many bytes. This way, the buffer can grow by more than what is immediately necessary, thus amortising the costs of allocating and copying.allowCompaction
-true
if the method is allowed to modify the reader offset and writer offset, otherwisefalse
.- Returns:
- This buffer instance.
-
If
-
copy
public Buffer copy()
Description copied from interface:Buffer
Returns a copy of this buffer's readable bytes. Modifying the content of the returned buffer will not affect this buffers contents. The two buffers will maintain separate offsets. This method is identical tobuf.copy(buf.readerOffset(), buf.readableBytes())
. This method does not modifyBuffer.readerOffset()
orBuffer.writerOffset()
of this buffer.The copy is created with a write offset equal to the length of the copied data, so that the entire contents of the copy is ready to be read.
The returned buffer will not be read-only, regardless of the read-only state of this buffer.
- Specified by:
copy
in interfaceBuffer
- Returns:
- A new buffer instance, with independent
Buffer.readerOffset()
andBuffer.writerOffset()
, that contains a copy of the readable region of this buffer.
-
copy
public Buffer copy(int offset, int length)
Description copied from interface:Buffer
Returns a copy of the given region of this buffer. Modifying the content of the returned buffer will not affect this buffers contents. The two buffers will maintain separate offsets. This method does not modifyBuffer.readerOffset()
orBuffer.writerOffset()
of this buffer.The copy is created with a write offset equal to the length of the copy, so that the entire contents of the copy is ready to be read.
The returned buffer will not be read-only, regardless of the read-only state of this buffer.
- Specified by:
copy
in interfaceBuffer
- Parameters:
offset
- The offset where copying should start from. This is the offset of the first byte copied.length
- The number of bytes to copy, and the capacity of the returned buffer.- Returns:
- A new buffer instance, with independent
Buffer.readerOffset()
andBuffer.writerOffset()
, that contains a copy of the given region of this buffer.
-
split
public Buffer split()
Description copied from interface:Buffer
Splits the buffer into two, at the write offset position.The region of this buffer that contain the previously read and readable bytes, will be captured and returned in a new buffer, that will hold its own ownership of that region. This allows the returned buffer to be independently sent to other threads.
The returned buffer will adopt the
Buffer.readerOffset()
of this buffer, and have itsBuffer.writerOffset()
andBuffer.capacity()
both set to the equal to the write-offset of this buffer.The memory region in the returned buffer will become inaccessible through this buffer. This buffer will have its capacity reduced by the capacity of the returned buffer, and the read and write offsets of this buffer will both become zero, even though their position in memory remain unchanged.
Effectively, the following transformation takes place:
When the buffers are in this state, both of the split parts retain an atomic reference count on the underlying memory. This means that shared underlying memory will not be deallocated or returned to a pool, until all the split parts have been closed.This buffer: +------------------------------------------+ 0| |r/o |w/o |cap +---+---------------------+----------------+ / / / \ \ / / / \ \ / / / \ \ / / / \ \ / / / \ \ +---+---------------------+ +---------------+ | |r/o |w/o & cap |r/o & w/o |cap +---+---------------------+ +---------------+ Returned buffer. This buffer.
Composite buffers have it a little easier, in that at most only one of the constituent buffers will actually be split. If the split point lands perfectly between two constituent buffers, then a composite buffer can simply split its internal array in two.
Split buffers support all operations that normal buffers do, including
Buffer.ensureWritable(int)
.See the Splitting buffers section for details.
-
split
public Buffer split(int splitOffset)
Description copied from interface:Buffer
Splits the buffer into two, at the givensplitOffset
.The region of this buffer that precede the
splitOffset
, will be captured and returned in a new buffer, that will hold its own ownership of that region. This allows the returned buffer to be independently sent to other threads.The returned buffer will adopt the
Buffer.readerOffset()
andBuffer.writerOffset()
of this buffer, but truncated to fit within the capacity dictated by thesplitOffset
.The memory region in the returned buffer will become inaccessible through this buffer. If the
Buffer.readerOffset()
orBuffer.writerOffset()
of this buffer lie prior to thesplitOffset
, then those offsets will be moved forward, so they land on offset 0 after the split.Effectively, the following transformation takes place:
When the buffers are in this state, both of the split parts retain an atomic reference count on the underlying memory. This means that shared underlying memory will not be deallocated or returned to a pool, until all the split parts have been closed.This buffer: +--------------------------------+ 0| |splitOffset |cap +---------------+----------------+ / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ +---------------+ +---------------+ | |cap | |cap +---------------+ +---------------+ Returned buffer. This buffer.
Composite buffers have it a little easier, in that at most only one of the constituent buffers will actually be split. If the split point lands perfectly between two constituent buffers, then a composite buffer can simply split its internal array in two.
Split buffers support all operations that normal buffers do, including
Buffer.ensureWritable(int)
.See the Splitting buffers section for details.
- Specified by:
split
in interfaceBuffer
- Parameters:
splitOffset
- The offset into this buffer where it should be split. After the split, the data at this offset will be at offset zero in this buffer.- Returns:
- A new buffer with independent and exclusive ownership over the bytes from the beginning to the given offset of this buffer.
-
compact
public Buffer compact()
Description copied from interface:Buffer
Discards the read bytes, and moves the buffer contents to the beginning of the buffer.
-
countComponents
public int countComponents()
Description copied from interface:Buffer
Get the number of "components" in this buffer. For composite buffers, this is the number of transitive constituent buffers, while non-composite buffers only have one component.- Specified by:
countComponents
in interfaceBuffer
- Returns:
- The number of components in this buffer.
-
countReadableComponents
public int countReadableComponents()
Description copied from interface:Buffer
Get the number of "components" in this buffer, that are readable. These are the components that would be processed byBuffer.forEachReadable(int, ReadableComponentProcessor)
. For composite buffers, this is the number of transitive constituent buffers that are readable, while non-composite buffers only have at most one readable component.The number of readable components may be less than the
component count
, if not all of them have readable data.- Specified by:
countReadableComponents
in interfaceBuffer
- Returns:
- The number of readable components in this buffer.
-
countWritableComponents
public int countWritableComponents()
Description copied from interface:Buffer
Get the number of "components" in this buffer, that are writable. These are the components that would be processed byBuffer.forEachWritable(int, WritableComponentProcessor)
. For composite buffers, this is the number of transitive constituent buffers that are writable, while non-composite buffers only have at most one writable component.The number of writable components may be less than the
component count
, if not all of them have space for writing.- Specified by:
countWritableComponents
in interfaceBuffer
- Returns:
- The number of writable components in this buffer.
-
forEachReadable
public <E extends Exception> int forEachReadable(int initialIndex, ReadableComponentProcessor<E> processor) throws E extends Exception
Description copied from interface:Buffer
Processes all readable components of this buffer, and return the number of components processed.The given processor is called for each readable component in this buffer, and passed a component index, for the given component in the iteration, and a
ReadableComponent
object for accessing the data within the given component.The component index is specific to the particular invocation of this method. The first call to the consumer will be passed the given initial index, and the next call will be passed the initial index plus one, and so on.
The component processor may stop the iteration at any time by returning
false
. This will cause the number of components processed to be returned as a negative number (to signal early return), and the number of components processed may then be less than the readable component count.Note that the
ReadableComponent
instance passed to the consumer could be reused for multiple calls, so the data must be extracted from the component in the context of the iteration.The
ByteBuffer
instances obtained from the component, share lifetime with that internal component. This means they can be accessed as long as the internal memory store remain unchanged. Methods that may cause such changes areBuffer.split(int)
,Buffer.split()
,Buffer.compact()
,Buffer.ensureWritable(int)
,Buffer.ensureWritable(int, int, boolean)
, andResource.send()
.The best way to ensure this doesn't cause any trouble, is to use the buffers directly as part of the iteration.
Note that the arrays, memory addresses, and byte buffers exposed as components by this method, should not be used for changing the buffer contents. Doing so may cause undefined behaviour.
Changes to position and limit of the byte buffers exposed via the processed components, are not reflected back to this buffer instance.
- Specified by:
forEachReadable
in interfaceBuffer
- Parameters:
initialIndex
- The initial index of the component for iteration, and the index that will be passed to the first call to the processor.processor
- The processor that will be used to process the buffer components.- Returns:
- The number of readable components processed, as a positive number if all readable components were
processed, or as a negative number if the iteration was stopped because
ReadableComponentProcessor.process(int, ReadableComponent)
returnedfalse
. In any case, the number of components processed may be less thanBuffer.countComponents()
. - Throws:
E extends Exception
-
forEachWritable
public <E extends Exception> int forEachWritable(int initialIndex, WritableComponentProcessor<E> processor) throws E extends Exception
Description copied from interface:Buffer
Process all writable components of this buffer, and return the number of components processed.The given processor is called for each writable component in this buffer, and passed a component index, for the given component in the iteration, and a
WritableComponent
object for accessing the data within the given component.The component index is specific to the particular invocation of this method. The first call to the consumer will be passed the given initial index, and the next call will be passed the initial index plus one, and so on.
The
component processor
may stop the iteration at any time by returningfalse
. This will cause the number of components processed to be returned as a negative number (to signal early return), and the number of components processed may then be less than the readable component count.Note that the
WritableComponent
instance passed to the consumer could be reused for multiple calls, so the data must be extracted from the component in the context of the iteration.The
ByteBuffer
instances obtained from the component, share lifetime with that internal component. This means they can be accessed as long as the internal memory store remain unchanged. Methods that may cause such changes areBuffer.split(int)
,Buffer.split()
,Buffer.compact()
,Buffer.ensureWritable(int)
,Buffer.ensureWritable(int, int, boolean)
, andResource.send()
.The best way to ensure this doesn't cause any trouble, is to use the buffers directly as part of the iteration.
Changes to position and limit of the byte buffers exposed via the processed components, are not reflected back to this buffer instance.
- Specified by:
forEachWritable
in interfaceBuffer
- Parameters:
initialIndex
- The initial index of the component for iteration, and the index that will be passed to the first call to the processor.processor
- The processor that will be used to process the buffer components.- Returns:
- The number of writable components processed, as a positive number if all writable components were
processed, or as a negative number if the iteration was stopped because
WritableComponentProcessor.process(int, WritableComponent)
returnedfalse
. In any case, the number of components processed may be less thanBuffer.countComponents()
. - Throws:
E extends Exception
-
readByte
public byte readByte()
Description copied from interface:BufferAccessor
Read the byte value at the currentBuffer.readerOffset()
, and increases the reader offset byByte.BYTES
. The value is read using a two's complement 8-bit encoding, inByteOrder.BIG_ENDIAN
byte order.- Specified by:
readByte
in interfaceBufferAccessor
- Returns:
- The byte value at the current reader offset.
-
getByte
public byte getByte(int roff)
Description copied from interface:BufferAccessor
Get the byte value at the given reader offset. TheBuffer.readerOffset()
is not modified. The value is read using a two's complement 8-bit encoding, inByteOrder.BIG_ENDIAN
byte order.- Specified by:
getByte
in interfaceBufferAccessor
- Parameters:
roff
- The read offset, an absolute offset into this buffer, to read from.- Returns:
- The byte value at the given offset.
-
readUnsignedByte
public int readUnsignedByte()
Description copied from interface:BufferAccessor
Read the unsigned byte value at the currentBuffer.readerOffset()
, and increases the reader offset byByte.BYTES
. The value is read using an unsigned two's complement 8-bit encoding, inByteOrder.BIG_ENDIAN
byte order.- Specified by:
readUnsignedByte
in interfaceBufferAccessor
- Returns:
- The unsigned byte value at the current reader offset.
-
getUnsignedByte
public int getUnsignedByte(int roff)
Description copied from interface:BufferAccessor
Get the unsigned byte value at the given reader offset. TheBuffer.readerOffset()
is not modified. The value is read using an unsigned two's complement 8-bit encoding, inByteOrder.BIG_ENDIAN
byte order.- Specified by:
getUnsignedByte
in interfaceBufferAccessor
- Parameters:
roff
- The read offset, an absolute offset into this buffer, to read from.- Returns:
- The unsigned byte value at the given offset.
-
writeByte
public Buffer writeByte(byte value)
Description copied from interface:BufferAccessor
Write the given byte value at the currentBuffer.writerOffset()
, and increase the writer offset byByte.BYTES
. The value is written using a two's complement 8-bit encoding, inByteOrder.BIG_ENDIAN
byte order.- Specified by:
writeByte
in interfaceBufferAccessor
- Parameters:
value
- The byte value to write.- Returns:
- This Buffer.
-
setByte
public Buffer setByte(int woff, byte value)
Description copied from interface:BufferAccessor
Set the given byte value at the given write offset. TheBuffer.writerOffset()
is not modified. The value is written using a two's complement 8-bit encoding, inByteOrder.BIG_ENDIAN
byte order.- Specified by:
setByte
in interfaceBufferAccessor
- Parameters:
woff
- The write offset, an absolute offset into this buffer to write to.value
- The byte value to write.- Returns:
- This Buffer.
-
writeUnsignedByte
public Buffer writeUnsignedByte(int value)
Description copied from interface:BufferAccessor
Write the given unsigned byte value at the currentBuffer.writerOffset()
, and increase the writer offset byByte.BYTES
. The value is written using an unsigned two's complement 8-bit encoding, inByteOrder.BIG_ENDIAN
byte order.- Specified by:
writeUnsignedByte
in interfaceBufferAccessor
- Parameters:
value
- The int value to write.- Returns:
- This Buffer.
-
setUnsignedByte
public Buffer setUnsignedByte(int woff, int value)
Description copied from interface:BufferAccessor
Set the given unsigned byte value at the given write offset. TheBuffer.writerOffset()
is not modified. The value is written using an unsigned two's complement 8-bit encoding, inByteOrder.BIG_ENDIAN
byte order.- Specified by:
setUnsignedByte
in interfaceBufferAccessor
- Parameters:
woff
- The write offset, an absolute offset into this buffer to write to.value
- The int value to write.- Returns:
- This Buffer.
-
readChar
public char readChar()
Description copied from interface:BufferAccessor
Read the char value at the currentBuffer.readerOffset()
, and increases the reader offset by 2. The value is read using a 2-byte UTF-16 encoding, inByteOrder.BIG_ENDIAN
byte order.- Specified by:
readChar
in interfaceBufferAccessor
- Returns:
- The char value at the current reader offset.
-
getChar
public char getChar(int roff)
Description copied from interface:BufferAccessor
Get the char value at the given reader offset. TheBuffer.readerOffset()
is not modified. The value is read using a 2-byte UTF-16 encoding, inByteOrder.BIG_ENDIAN
byte order.- Specified by:
getChar
in interfaceBufferAccessor
- Parameters:
roff
- The read offset, an absolute offset into this buffer, to read from.- Returns:
- The char value at the given offset.
-
writeChar
public Buffer writeChar(char value)
Description copied from interface:BufferAccessor
Write the given char value at the currentBuffer.writerOffset()
, and increase the writer offset by 2. The value is written using a 2-byte UTF-16 encoding, inByteOrder.BIG_ENDIAN
byte order.- Specified by:
writeChar
in interfaceBufferAccessor
- Parameters:
value
- The char value to write.- Returns:
- This Buffer.
-
setChar
public Buffer setChar(int woff, char value)
Description copied from interface:BufferAccessor
Set the given char value at the given write offset. TheBuffer.writerOffset()
is not modified. The value is written using a 2-byte UTF-16 encoding, inByteOrder.BIG_ENDIAN
byte order.- Specified by:
setChar
in interfaceBufferAccessor
- Parameters:
woff
- The write offset, an absolute offset into this buffer to write to.value
- The char value to write.- Returns:
- This Buffer.
-
readShort
public short readShort()
Description copied from interface:BufferAccessor
Read the short value at the currentBuffer.readerOffset()
, and increases the reader offset byShort.BYTES
. The value is read using a two's complement 16-bit encoding, inByteOrder.BIG_ENDIAN
byte order.- Specified by:
readShort
in interfaceBufferAccessor
- Returns:
- The short value at the current reader offset.
-
getShort
public short getShort(int roff)
Description copied from interface:BufferAccessor
Get the short value at the given reader offset. TheBuffer.readerOffset()
is not modified. The value is read using a two's complement 16-bit encoding, inByteOrder.BIG_ENDIAN
byte order.- Specified by:
getShort
in interfaceBufferAccessor
- Parameters:
roff
- The read offset, an absolute offset into this buffer, to read from.- Returns:
- The short value at the given offset.
-
readUnsignedShort
public int readUnsignedShort()
Description copied from interface:BufferAccessor
Read the unsigned short value at the currentBuffer.readerOffset()
, and increases the reader offset byShort.BYTES
. The value is read using an unsigned two's complement 16-bit encoding, inByteOrder.BIG_ENDIAN
byte order.- Specified by:
readUnsignedShort
in interfaceBufferAccessor
- Returns:
- The unsigned short value at the current reader offset.
-
getUnsignedShort
public int getUnsignedShort(int roff)
Description copied from interface:BufferAccessor
Get the unsigned short value at the given reader offset. TheBuffer.readerOffset()
is not modified. The value is read using an unsigned two's complement 16-bit encoding, inByteOrder.BIG_ENDIAN
byte order.- Specified by:
getUnsignedShort
in interfaceBufferAccessor
- Parameters:
roff
- The read offset, an absolute offset into this buffer, to read from.- Returns:
- The unsigned short value at the given offset.
-
writeShort
public Buffer writeShort(short value)
Description copied from interface:BufferAccessor
Write the given short value at the currentBuffer.writerOffset()
, and increase the writer offset byShort.BYTES
. The value is written using a two's complement 16-bit encoding, inByteOrder.BIG_ENDIAN
byte order.- Specified by:
writeShort
in interfaceBufferAccessor
- Parameters:
value
- The short value to write.- Returns:
- This Buffer.
-
setShort
public Buffer setShort(int woff, short value)
Description copied from interface:BufferAccessor
Set the given short value at the given write offset. TheBuffer.writerOffset()
is not modified. The value is written using a two's complement 16-bit encoding, inByteOrder.BIG_ENDIAN
byte order.- Specified by:
setShort
in interfaceBufferAccessor
- Parameters:
woff
- The write offset, an absolute offset into this buffer to write to.value
- The short value to write.- Returns:
- This Buffer.
-
writeUnsignedShort
public Buffer writeUnsignedShort(int value)
Description copied from interface:BufferAccessor
Write the given unsigned short value at the currentBuffer.writerOffset()
, and increase the writer offset byShort.BYTES
. The value is written using an unsigned two's complement 16-bit encoding, inByteOrder.BIG_ENDIAN
byte order.- Specified by:
writeUnsignedShort
in interfaceBufferAccessor
- Parameters:
value
- The int value to write.- Returns:
- This Buffer.
-
setUnsignedShort
public Buffer setUnsignedShort(int woff, int value)
Description copied from interface:BufferAccessor
Set the given unsigned short value at the given write offset. TheBuffer.writerOffset()
is not modified. The value is written using an unsigned two's complement 16-bit encoding, inByteOrder.BIG_ENDIAN
byte order.- Specified by:
setUnsignedShort
in interfaceBufferAccessor
- Parameters:
woff
- The write offset, an absolute offset into this buffer to write to.value
- The int value to write.- Returns:
- This Buffer.
-
readMedium
public int readMedium()
Description copied from interface:BufferAccessor
Read the int value at the currentBuffer.readerOffset()
, and increases the reader offset by 3. The value is read using a two's complement 24-bit encoding, inByteOrder.BIG_ENDIAN
byte order.- Specified by:
readMedium
in interfaceBufferAccessor
- Returns:
- The int value at the current reader offset.
-
getMedium
public int getMedium(int roff)
Description copied from interface:BufferAccessor
Get the int value at the given reader offset. TheBuffer.readerOffset()
is not modified. The value is read using a two's complement 24-bit encoding, inByteOrder.BIG_ENDIAN
byte order.- Specified by:
getMedium
in interfaceBufferAccessor
- Parameters:
roff
- The read offset, an absolute offset into this buffer, to read from.- Returns:
- The int value at the given offset.
-
readUnsignedMedium
public int readUnsignedMedium()
Description copied from interface:BufferAccessor
Read the unsigned int value at the currentBuffer.readerOffset()
, and increases the reader offset by 3. The value is read using an unsigned two's complement 24-bit encoding, inByteOrder.BIG_ENDIAN
byte order.- Specified by:
readUnsignedMedium
in interfaceBufferAccessor
- Returns:
- The unsigned int value at the current reader offset.
-
getUnsignedMedium
public int getUnsignedMedium(int roff)
Description copied from interface:BufferAccessor
Get the unsigned int value at the given reader offset. TheBuffer.readerOffset()
is not modified. The value is read using an unsigned two's complement 24-bit encoding, inByteOrder.BIG_ENDIAN
byte order.- Specified by:
getUnsignedMedium
in interfaceBufferAccessor
- Parameters:
roff
- The read offset, an absolute offset into this buffer, to read from.- Returns:
- The unsigned int value at the given offset.
-
writeMedium
public Buffer writeMedium(int value)
Description copied from interface:BufferAccessor
Write the given int value at the currentBuffer.writerOffset()
, and increase the writer offset by 3. The value is written using a two's complement 24-bit encoding, inByteOrder.BIG_ENDIAN
byte order.- Specified by:
writeMedium
in interfaceBufferAccessor
- Parameters:
value
- The int value to write.- Returns:
- This Buffer.
-
setMedium
public Buffer setMedium(int woff, int value)
Description copied from interface:BufferAccessor
Set the given int value at the given write offset. TheBuffer.writerOffset()
is not modified. The value is written using a two's complement 24-bit encoding, inByteOrder.BIG_ENDIAN
byte order.- Specified by:
setMedium
in interfaceBufferAccessor
- Parameters:
woff
- The write offset, an absolute offset into this buffer to write to.value
- The int value to write.- Returns:
- This Buffer.
-
writeUnsignedMedium
public Buffer writeUnsignedMedium(int value)
Description copied from interface:BufferAccessor
Write the given unsigned int value at the currentBuffer.writerOffset()
, and increase the writer offset by 3. The value is written using an unsigned two's complement 24-bit encoding, inByteOrder.BIG_ENDIAN
byte order.- Specified by:
writeUnsignedMedium
in interfaceBufferAccessor
- Parameters:
value
- The int value to write.- Returns:
- This Buffer.
-
setUnsignedMedium
public Buffer setUnsignedMedium(int woff, int value)
Description copied from interface:BufferAccessor
Set the given unsigned int value at the given write offset. TheBuffer.writerOffset()
is not modified. The value is written using an unsigned two's complement 24-bit encoding, inByteOrder.BIG_ENDIAN
byte order.- Specified by:
setUnsignedMedium
in interfaceBufferAccessor
- Parameters:
woff
- The write offset, an absolute offset into this buffer to write to.value
- The int value to write.- Returns:
- This Buffer.
-
readInt
public int readInt()
Description copied from interface:BufferAccessor
Read the int value at the currentBuffer.readerOffset()
, and increases the reader offset byInteger.BYTES
. The value is read using a two's complement 32-bit encoding, inByteOrder.BIG_ENDIAN
byte order.- Specified by:
readInt
in interfaceBufferAccessor
- Returns:
- The int value at the current reader offset.
-
getInt
public int getInt(int roff)
Description copied from interface:BufferAccessor
Get the int value at the given reader offset. TheBuffer.readerOffset()
is not modified. The value is read using a two's complement 32-bit encoding, inByteOrder.BIG_ENDIAN
byte order.- Specified by:
getInt
in interfaceBufferAccessor
- Parameters:
roff
- The read offset, an absolute offset into this buffer, to read from.- Returns:
- The int value at the given offset.
-
readUnsignedInt
public long readUnsignedInt()
Description copied from interface:BufferAccessor
Read the unsigned int value at the currentBuffer.readerOffset()
, and increases the reader offset byInteger.BYTES
. The value is read using an unsigned two's complement 32-bit encoding, inByteOrder.BIG_ENDIAN
byte order.- Specified by:
readUnsignedInt
in interfaceBufferAccessor
- Returns:
- The unsigned int value at the current reader offset.
-
getUnsignedInt
public long getUnsignedInt(int roff)
Description copied from interface:BufferAccessor
Get the unsigned int value at the given reader offset. TheBuffer.readerOffset()
is not modified. The value is read using an unsigned two's complement 32-bit encoding, inByteOrder.BIG_ENDIAN
byte order.- Specified by:
getUnsignedInt
in interfaceBufferAccessor
- Parameters:
roff
- The read offset, an absolute offset into this buffer, to read from.- Returns:
- The unsigned int value at the given offset.
-
writeInt
public Buffer writeInt(int value)
Description copied from interface:BufferAccessor
Write the given int value at the currentBuffer.writerOffset()
, and increase the writer offset byInteger.BYTES
. The value is written using a two's complement 32-bit encoding, inByteOrder.BIG_ENDIAN
byte order.- Specified by:
writeInt
in interfaceBufferAccessor
- Parameters:
value
- The int value to write.- Returns:
- This Buffer.
-
setInt
public Buffer setInt(int woff, int value)
Description copied from interface:BufferAccessor
Set the given int value at the given write offset. TheBuffer.writerOffset()
is not modified. The value is written using a two's complement 32-bit encoding, inByteOrder.BIG_ENDIAN
byte order.- Specified by:
setInt
in interfaceBufferAccessor
- Parameters:
woff
- The write offset, an absolute offset into this buffer to write to.value
- The int value to write.- Returns:
- This Buffer.
-
writeUnsignedInt
public Buffer writeUnsignedInt(long value)
Description copied from interface:BufferAccessor
Write the given unsigned int value at the currentBuffer.writerOffset()
, and increase the writer offset byInteger.BYTES
. The value is written using an unsigned two's complement 32-bit encoding, inByteOrder.BIG_ENDIAN
byte order.- Specified by:
writeUnsignedInt
in interfaceBufferAccessor
- Parameters:
value
- The long value to write.- Returns:
- This Buffer.
-
setUnsignedInt
public Buffer setUnsignedInt(int woff, long value)
Description copied from interface:BufferAccessor
Set the given unsigned int value at the given write offset. TheBuffer.writerOffset()
is not modified. The value is written using an unsigned two's complement 32-bit encoding, inByteOrder.BIG_ENDIAN
byte order.- Specified by:
setUnsignedInt
in interfaceBufferAccessor
- Parameters:
woff
- The write offset, an absolute offset into this buffer to write to.value
- The long value to write.- Returns:
- This Buffer.
-
readFloat
public float readFloat()
Description copied from interface:BufferAccessor
Read the float value at the currentBuffer.readerOffset()
, and increases the reader offset byFloat.BYTES
. The value is read using a 32-bit IEEE floating point encoding, inByteOrder.BIG_ENDIAN
byte order.- Specified by:
readFloat
in interfaceBufferAccessor
- Returns:
- The float value at the current reader offset.
-
getFloat
public float getFloat(int roff)
Description copied from interface:BufferAccessor
Get the float value at the given reader offset. TheBuffer.readerOffset()
is not modified. The value is read using a 32-bit IEEE floating point encoding, inByteOrder.BIG_ENDIAN
byte order.- Specified by:
getFloat
in interfaceBufferAccessor
- Parameters:
roff
- The read offset, an absolute offset into this buffer, to read from.- Returns:
- The float value at the given offset.
-
writeFloat
public Buffer writeFloat(float value)
Description copied from interface:BufferAccessor
Write the given float value at the currentBuffer.writerOffset()
, and increase the writer offset byFloat.BYTES
. The value is written using a 32-bit IEEE floating point encoding, inByteOrder.BIG_ENDIAN
byte order.- Specified by:
writeFloat
in interfaceBufferAccessor
- Parameters:
value
- The float value to write.- Returns:
- This Buffer.
-
setFloat
public Buffer setFloat(int woff, float value)
Description copied from interface:BufferAccessor
Set the given float value at the given write offset. TheBuffer.writerOffset()
is not modified. The value is written using a 32-bit IEEE floating point encoding, inByteOrder.BIG_ENDIAN
byte order.- Specified by:
setFloat
in interfaceBufferAccessor
- Parameters:
woff
- The write offset, an absolute offset into this buffer to write to.value
- The float value to write.- Returns:
- This Buffer.
-
readLong
public long readLong()
Description copied from interface:BufferAccessor
Read the long value at the currentBuffer.readerOffset()
, and increases the reader offset byLong.BYTES
. The value is read using a two's complement 64-bit encoding, inByteOrder.BIG_ENDIAN
byte order.- Specified by:
readLong
in interfaceBufferAccessor
- Returns:
- The long value at the current reader offset.
-
getLong
public long getLong(int roff)
Description copied from interface:BufferAccessor
Get the long value at the given reader offset. TheBuffer.readerOffset()
is not modified. The value is read using a two's complement 64-bit encoding, inByteOrder.BIG_ENDIAN
byte order.- Specified by:
getLong
in interfaceBufferAccessor
- Parameters:
roff
- The read offset, an absolute offset into this buffer, to read from.- Returns:
- The long value at the given offset.
-
writeLong
public Buffer writeLong(long value)
Description copied from interface:BufferAccessor
Write the given long value at the currentBuffer.writerOffset()
, and increase the writer offset byLong.BYTES
. The value is written using a two's complement 64-bit encoding, inByteOrder.BIG_ENDIAN
byte order.- Specified by:
writeLong
in interfaceBufferAccessor
- Parameters:
value
- The long value to write.- Returns:
- This Buffer.
-
setLong
public Buffer setLong(int woff, long value)
Description copied from interface:BufferAccessor
Set the given long value at the given write offset. TheBuffer.writerOffset()
is not modified. The value is written using a two's complement 64-bit encoding, inByteOrder.BIG_ENDIAN
byte order.- Specified by:
setLong
in interfaceBufferAccessor
- Parameters:
woff
- The write offset, an absolute offset into this buffer to write to.value
- The long value to write.- Returns:
- This Buffer.
-
readDouble
public double readDouble()
Description copied from interface:BufferAccessor
Read the double value at the currentBuffer.readerOffset()
, and increases the reader offset byDouble.BYTES
. The value is read using a 64-bit IEEE floating point encoding, inByteOrder.BIG_ENDIAN
byte order.- Specified by:
readDouble
in interfaceBufferAccessor
- Returns:
- The double value at the current reader offset.
-
getDouble
public double getDouble(int roff)
Description copied from interface:BufferAccessor
Get the double value at the given reader offset. TheBuffer.readerOffset()
is not modified. The value is read using a 64-bit IEEE floating point encoding, inByteOrder.BIG_ENDIAN
byte order.- Specified by:
getDouble
in interfaceBufferAccessor
- Parameters:
roff
- The read offset, an absolute offset into this buffer, to read from.- Returns:
- The double value at the given offset.
-
writeDouble
public Buffer writeDouble(double value)
Description copied from interface:BufferAccessor
Write the given double value at the currentBuffer.writerOffset()
, and increase the writer offset byDouble.BYTES
. The value is written using a 64-bit IEEE floating point encoding, inByteOrder.BIG_ENDIAN
byte order.- Specified by:
writeDouble
in interfaceBufferAccessor
- Parameters:
value
- The double value to write.- Returns:
- This Buffer.
-
setDouble
public Buffer setDouble(int woff, double value)
Description copied from interface:BufferAccessor
Set the given double value at the given write offset. TheBuffer.writerOffset()
is not modified. The value is written using a 64-bit IEEE floating point encoding, inByteOrder.BIG_ENDIAN
byte order.- Specified by:
setDouble
in interfaceBufferAccessor
- Parameters:
woff
- The write offset, an absolute offset into this buffer to write to.value
- The double value to write.- Returns:
- This Buffer.
-
send
public Send<Buffer> send()
Description copied from interface:Resource
Send this object instance to another Thread, transferring the ownership to the recipient.The object must be in a state where it can be sent, which includes at least being accessible.
When sent, this instance will immediately become inaccessible, as if by closing it. All attempts at accessing an object that has been sent, even if that object has not yet been received, should cause an exception to be thrown.
Calling
Resource.close()
on an object that has been sent will have no effect, so this method is safe to call within a try-with-resources statement.
-
close
public void close()
Description copied from interface:Resource
Close the resource, making it inaccessible.Note, this method is not thread-safe unless otherwise specified.
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceResource<Buffer>
-
isAccessible
public boolean isAccessible()
Description copied from interface:Resource
Check if this object is accessible.- Specified by:
isAccessible
in interfaceResource<Buffer>
- Returns:
true
if this object is still valid and can be accessed, otherwisefalse
if, for instance, this object has been dropped/deallocated, or been sent elsewhere.
-
touch
public Buffer touch(Object hint)
Description copied from interface:Resource
Record the current access location for debugging purposes. This information may be included if the resource throws a life-cycle related exception, or if it leaks. If this resource has already been closed, then this method has no effect.
-
toString
public String toString(Charset charset)
Description copied from interface:Buffer
Decodes this buffer's readable bytes into a string with the specified Charset.This method does not modify the reader or writer offset of this buffer.
-
-