- java.lang.Object
-
- io.netty5.buffer.api.BufferStub
-
- All Implemented Interfaces:
Buffer,BufferAccessor,io.netty5.util.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 intbytesBefore(byte needle)Get the number of readable bytes, until the givenneedleis found in this buffer.intbytesBefore(Buffer needle)Get the number of readable bytes, until the givenneedleis found in this buffer.intcapacity()The capacity of this buffer, that is, the maximum number of bytes it can contain.voidclose()Buffercompact()Discards the read bytes, and moves the buffer contents to the beginning of the buffer.Buffercopy()Returns a copy of this buffer's readable bytes.Buffercopy(boolean readOnly)Returns a copy of this buffer's readable bytes, with the given read-only setting.Buffercopy(int offset, int length)Returns a copy of the given region of this buffer.Buffercopy(int offset, int length, boolean readOnly)Returns a copy of the given region of this buffer.voidcopyInto(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.voidcopyInto(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.voidcopyInto(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.intcountComponents()Get the number of "components" in this buffer.intcountReadableComponents()Get the number of "components" in this buffer, that are readable.intcountWritableComponents()Get the number of "components" in this buffer, that are writable.BufferensureWritable(int size)Ensures that this buffer has at least the given number of bytes of available space for writing.BufferensureWritable(int size, int minimumGrowth, boolean allowCompaction)Ensures that this buffer has at least the given number of bytes of available space for writing.booleanequals(Object obj)Bufferfill(byte value)Fills the buffer with the given byte value.<T extends ReadableComponent & ComponentIterator.Next>
ComponentIterator<T>forEachReadable()Create a component iterator for all readable components in this buffer.<E extends Exception>
intforEachReadable(int initialIndex, ReadableComponentProcessor<E> processor)Processes all readable components of this buffer, and return the number of components processed.<T extends WritableComponent & ComponentIterator.Next>
ComponentIterator<T>forEachWritable()Create a component iterator for all writable components in this buffer.<E extends Exception>
intforEachWritable(int initialIndex, WritableComponentProcessor<E> processor)Process all writable components of this buffer, and return the number of components processed.booleangetBoolean(int roff)Get the boolean value at the given reader offset.bytegetByte(int roff)Get the byte value at the given reader offset.chargetChar(int roff)Get the char value at the given reader offset.doublegetDouble(int roff)Get the double value at the given reader offset.floatgetFloat(int roff)Get the float value at the given reader offset.intgetInt(int roff)Get the int value at the given reader offset.longgetLong(int roff)Get the long value at the given reader offset.intgetMedium(int roff)Get the int value at the given reader offset.shortgetShort(int roff)Get the short value at the given reader offset.intgetUnsignedByte(int roff)Get the unsigned byte value at the given reader offset.longgetUnsignedInt(int roff)Get the unsigned int value at the given reader offset.intgetUnsignedMedium(int roff)Get the unsigned int value at the given reader offset.intgetUnsignedShort(int roff)Get the unsigned short value at the given reader offset.inthashCode()intimplicitCapacityLimit()Returns the implicit capacity limit of the buffer.BufferimplicitCapacityLimit(int limit)Set an upper limit to the implicit capacity growth.booleanisAccessible()booleanisDirect()Queries if this buffer is backed by native memory, or not.BuffermakeReadOnly()Makes this buffer read-only.ByteCursoropenCursor()Opens a cursor to iterate the readable bytes of this buffer.ByteCursoropenCursor(int fromOffset, int length)Opens a cursor to iterate the given number bytes of this buffer, starting at the given offset.ByteCursoropenReverseCursor()Opens a cursor to iterate the readable bytes of this buffer, in reverse.ByteCursoropenReverseCursor(int fromOffset, int length)Opens a cursor to iterate the given number bytes of this buffer, in reverse, starting at the given offset.intreadableBytes()Returns the number of readable bytes which is equal to(writerOffset() - readerOffset()).booleanreadBoolean()Read the boolean value at the currentBuffer.readerOffset(), and increases the reader offset byByte.BYTES.bytereadByte()Read the byte value at the currentBuffer.readerOffset(), and increases the reader offset byByte.BYTES.BufferreadBytes(byte[] destination, int destPos, int length)Read from this buffer, into the destination array, the given number of bytes.BufferreadBytes(ByteBuffer destination)Read from this buffer, into the destinationByteBufferThis updates the read offset of this buffer and also the position of the destinationByteBuffer.charreadChar()Read the char value at the currentBuffer.readerOffset(), and increases the reader offset by 2.CharSequencereadCharSequence(int length, Charset charset)doublereadDouble()Read the double value at the currentBuffer.readerOffset(), and increases the reader offset byDouble.BYTES.intreaderOffset()Get the current reader offset.BufferreaderOffset(int offset)Set the reader offset.floatreadFloat()Read the float value at the currentBuffer.readerOffset(), and increases the reader offset byFloat.BYTES.intreadInt()Read the int value at the currentBuffer.readerOffset(), and increases the reader offset byInteger.BYTES.longreadLong()Read the long value at the currentBuffer.readerOffset(), and increases the reader offset byLong.BYTES.intreadMedium()Read the int value at the currentBuffer.readerOffset(), and increases the reader offset by 3.booleanreadOnly()Queries if this buffer is read-only or not.shortreadShort()Read the short value at the currentBuffer.readerOffset(), and increases the reader offset byShort.BYTES.BufferreadSplit(int length)Splits the buffer into two, atlengthnumber of bytes from the current Buffer.readerOffset() reader offset} position.intreadUnsignedByte()Read the unsigned byte value at the currentBuffer.readerOffset(), and increases the reader offset byByte.BYTES.longreadUnsignedInt()Read the unsigned int value at the currentBuffer.readerOffset(), and increases the reader offset byInteger.BYTES.intreadUnsignedMedium()Read the unsigned int value at the currentBuffer.readerOffset(), and increases the reader offset by 3.intreadUnsignedShort()Read the unsigned short value at the currentBuffer.readerOffset(), and increases the reader offset byShort.BYTES.BufferresetOffsets()Resets the read offset and the write offset on this buffer to zero, and return this buffer.io.netty5.util.Send<Buffer>send()BuffersetBoolean(int woff, boolean value)Set the given boolean value at the given write offset.BuffersetByte(int woff, byte value)Set the given byte value at the given write offset.BuffersetChar(int woff, char value)Set the given char value at the given write offset.BuffersetDouble(int woff, double value)Set the given double value at the given write offset.BuffersetFloat(int woff, float value)Set the given float value at the given write offset.BuffersetInt(int woff, int value)Set the given int value at the given write offset.BuffersetLong(int woff, long value)Set the given long value at the given write offset.BuffersetMedium(int woff, int value)Set the given int value at the given write offset.BuffersetShort(int woff, short value)Set the given short value at the given write offset.BuffersetUnsignedByte(int woff, int value)Set the given unsigned byte value at the given write offset.BuffersetUnsignedInt(int woff, long value)Set the given unsigned int value at the given write offset.BuffersetUnsignedMedium(int woff, int value)Set the given unsigned int value at the given write offset.BuffersetUnsignedShort(int woff, int value)Set the given unsigned short value at the given write offset.BufferskipReadableBytes(int delta)Move the reader offset forward by the given delta.BufferskipWritableBytes(int delta)Move the writer offset to ahead by the given delta.Buffersplit()Splits the buffer into two, at the write offset position.Buffersplit(int splitOffset)Splits the buffer into two, at the givensplitOffset.StringtoString(Charset charset)Decodes this buffer's readable bytes into a string with the specified Charset.Buffertouch(Object hint)inttransferFrom(FileChannel channel, long position, int length)Read from the given channel starting from the given position and write to this buffer.inttransferFrom(ReadableByteChannel channel, int length)Read from the given channel and write to this buffer.inttransferTo(WritableByteChannel channel, int length)Read from this buffer and write to the given channel.intwritableBytes()Returns the number of writable bytes which is equal to(capacity() - writerOffset()).BufferwriteBoolean(boolean value)Write the given boolean value at the currentBuffer.writerOffset(), and increase the writer offset byByte.BYTES.BufferwriteByte(byte value)Write the given byte value at the currentBuffer.writerOffset(), and increase the writer offset byByte.BYTES.BufferwriteBytes(byte[] source)Writes into this buffer, all the bytes from the given byte array.BufferwriteBytes(byte[] source, int srcPos, int length)Writes into this buffer, the given number of bytes from the byte array.BufferwriteBytes(Buffer source)Writes into this buffer, all the readable bytes from the given buffer.BufferwriteBytes(ByteBuffer source)Writes into this buffer from the sourceByteBuffer.BufferwriteChar(char value)Write the given char value at the currentBuffer.writerOffset(), and increase the writer offset by 2.BufferwriteCharSequence(CharSequence source, Charset charset)Writes into this buffer, all the bytes from the givensourceusing the passedcharset.BufferwriteDouble(double value)Write the given double value at the currentBuffer.writerOffset(), and increase the writer offset byDouble.BYTES.BufferwriteFloat(float value)Write the given float value at the currentBuffer.writerOffset(), and increase the writer offset byFloat.BYTES.BufferwriteInt(int value)Write the given int value at the currentBuffer.writerOffset(), and increase the writer offset byInteger.BYTES.BufferwriteLong(long value)Write the given long value at the currentBuffer.writerOffset(), and increase the writer offset byLong.BYTES.BufferwriteMedium(int value)Write the given int value at the currentBuffer.writerOffset(), and increase the writer offset by 3.intwriterOffset()Get the current writer offset.BufferwriterOffset(int offset)Set the writer offset.BufferwriteShort(short value)Write the given short value at the currentBuffer.writerOffset(), and increase the writer offset byShort.BYTES.BufferwriteSplit(int length)Splits the buffer into two, atlengthnumber of bytes from the current Buffer.writerOffset() writer offset} position.BufferwriteUnsignedByte(int value)Write the given unsigned byte value at the currentBuffer.writerOffset(), and increase the writer offset byByte.BYTES.BufferwriteUnsignedInt(long value)Write the given unsigned int value at the currentBuffer.writerOffset(), and increase the writer offset byInteger.BYTES.BufferwriteUnsignedMedium(int value)Write the given unsigned int value at the currentBuffer.writerOffset(), and increase the writer offset by 3.BufferwriteUnsignedShort(int value)Write the given unsigned short value at the currentBuffer.writerOffset(), and increase the writer offset byShort.BYTES.
-
-
-
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:BufferThe capacity of this buffer, that is, the maximum number of bytes it can contain.
-
readerOffset
public int readerOffset()
Description copied from interface:BufferGet the current reader offset. The next read will happen from this byte offset into the buffer.- Specified by:
readerOffsetin interfaceBuffer- Returns:
- The current reader offset.
-
skipReadableBytes
public Buffer skipReadableBytes(int delta)
Description copied from interface:BufferMove the reader offset forward by the given delta.- Specified by:
skipReadableBytesin interfaceBuffer- Parameters:
delta- to accumulate.- Returns:
- This buffer instance.
-
readerOffset
public Buffer readerOffset(int offset)
Description copied from interface:BufferSet the reader offset. Make the next read happen from the given offset into the buffer.- Specified by:
readerOffsetin interfaceBuffer- Parameters:
offset- The reader offset to set.- Returns:
- This Buffer.
-
writerOffset
public int writerOffset()
Description copied from interface:BufferGet the current writer offset. The next write will happen at this byte offset into the buffer.- Specified by:
writerOffsetin interfaceBuffer- Returns:
- The current writer offset.
-
skipWritableBytes
public Buffer skipWritableBytes(int delta)
Description copied from interface:BufferMove the writer offset to ahead by the given delta.- Specified by:
skipWritableBytesin interfaceBuffer- Parameters:
delta- to accumulate.- Returns:
- This buffer instance.
-
writerOffset
public Buffer writerOffset(int offset)
Description copied from interface:BufferSet the writer offset. Make the next write happen at the given offset.- Specified by:
writerOffsetin interfaceBuffer- Parameters:
offset- The writer offset to set.- Returns:
- This Buffer.
-
readableBytes
public int readableBytes()
Description copied from interface:BufferReturns the number of readable bytes which is equal to(writerOffset() - readerOffset()).- Specified by:
readableBytesin interfaceBuffer
-
writableBytes
public int writableBytes()
Description copied from interface:BufferReturns the number of writable bytes which is equal to(capacity() - writerOffset()).- Specified by:
writableBytesin interfaceBuffer
-
fill
public Buffer fill(byte value)
Description copied from interface:BufferFills 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:BufferMakes 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:
makeReadOnlyin interfaceBuffer- Returns:
- This buffer instance.
-
readOnly
public boolean readOnly()
Description copied from interface:BufferQueries if this buffer is read-only or not.
-
isDirect
public boolean isDirect()
Description copied from interface:BufferQueries if this buffer is backed by native memory, or not.
-
implicitCapacityLimit
public Buffer implicitCapacityLimit(int limit)
Description copied from interface:BufferSet an upper limit to the implicit capacity growth. Bufferwrite*methods may implicitly grow the buffer capacity instead of throwing a bounds check exception. The implicit capacity limit restricts this growth so the buffer capacity does not automatically grow beyond the given limit. When the limit is reached, and there is no more writable space left, then thewrite*methods will start throwing exceptions.The default limit is the maximum buffer size.
The limit is carried through
Resource.send()calls, but the buffer instances returned from the varioussplitandcopymethods will have the default limit set.The limit is not impacted by calls to
splitmethods on this buffer. In other words, even thoughsplitmethods reduce the capacity of this buffer, the set limit, if any, remains the same.- Specified by:
implicitCapacityLimitin interfaceBuffer- Parameters:
limit- The maximum size this buffers capacity will implicitly grow to viawrite*methods.- Returns:
- This buffer instance.
-
implicitCapacityLimit
public int implicitCapacityLimit()
Description copied from interface:BufferReturns the implicit capacity limit of the buffer. If none was set before viaBuffer.implicitCapacityLimit(int)this method will return the default value.- Specified by:
implicitCapacityLimitin interfaceBuffer- Returns:
- the limit.
-
copyInto
public void copyInto(int srcPos, byte[] dest, int destPos, int length)Description copied from interface:BufferCopies 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:
copyIntoin 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 thedestPosindex in thedestarray.dest- The destination byte array.destPos- The index into thedestarray 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:BufferCopies 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
destPosorlength.- Specified by:
copyIntoin 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 thedestPosindex in thedestarray.dest- The destination byte buffer.destPos- The index into thedestarray 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:BufferCopies 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
destPosorlength.- Specified by:
copyIntoin 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 thedestPosindex in thedestarray.dest- The destination buffer.destPos- The index into thedestarray 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:BufferRead from this buffer and write to the given channel. The number of bytes actually written to the channel are returned. No more than the givenlengthof 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:
transferToin 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(FileChannel channel, long position, int length) throws IOException
Description copied from interface:BufferRead from the given channel starting from the given position 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 givenlengthof bytes, or the number of writable bytes, will be read from the channel, whichever is smaller. The channel's position is not modified. The writer-offset of this buffer will likewise be advanced by the number of bytes read.- Specified by:
transferFromin interfaceBuffer- Parameters:
channel- The channel to read from.position- The file position.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.
-
transferFrom
public int transferFrom(ReadableByteChannel channel, int length) throws IOException
Description copied from interface:BufferRead 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 givenlengthof 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:
transferFromin 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:BufferWrites 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:
writeBytesin interfaceBuffer- Parameters:
source- The buffer to read from.- Returns:
- This buffer.
-
writeBytes
public Buffer writeBytes(byte[] source)
Description copied from interface:BufferWrites 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:
writeBytesin interfaceBuffer- Parameters:
source- The byte array to read from.- Returns:
- This buffer.
-
resetOffsets
public Buffer resetOffsets()
Description copied from interface:BufferResets the read offset and the write offset on this buffer to zero, and return this buffer.- Specified by:
resetOffsetsin interfaceBuffer- Returns:
- This buffer instance.
-
bytesBefore
public int bytesBefore(byte needle)
Description copied from interface:BufferGet the number of readable bytes, until the givenneedleis found in this buffer. If the needle is not found,-1is returned.This method does not modify the reader-offset or the write-offset.
- Specified by:
bytesBeforein interfaceBuffer- Parameters:
needle- The byte value to search for.- Returns:
- The offset, relative to the current
Buffer.readerOffset(), of the found value, or-1if none was found.
-
bytesBefore
public int bytesBefore(Buffer needle)
Description copied from interface:BufferGet the number of readable bytes, until the givenneedleis found in this buffer. The found offset will be the offset into this buffer, relative to its reader-offset, of the first byte of a sequence that matches all readable bytes in the givenneedlebuffer. If the needle is not found,-1is returned.This method does not modify the reader-offset or the write-offset.
- Specified by:
bytesBeforein interfaceBuffer- Parameters:
needle- The buffer value to search for.- Returns:
- The offset, relative to the current
Buffer.readerOffset(), of the found value, or-1if none was found.
-
openCursor
public ByteCursor openCursor()
Description copied from interface:BufferOpens 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:
openCursorin interfaceBuffer- Returns:
- A
ByteCursorfor iterating the readable bytes of this buffer.
-
openCursor
public ByteCursor openCursor(int fromOffset, int length)
Description copied from interface:BufferOpens 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:
openCursorin 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
ByteCursorfor the given stretch of bytes of this buffer.
-
openReverseCursor
public ByteCursor openReverseCursor()
Description copied from interface:BufferOpens 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:
openReverseCursorin interfaceBuffer- Returns:
- A
ByteCursorfor the readable bytes of this buffer.
-
openReverseCursor
public ByteCursor openReverseCursor(int fromOffset, int length)
Description copied from interface:BufferOpens 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:
openReverseCursorin 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
ByteCursorfor the given stretch of bytes of this buffer.
-
ensureWritable
public Buffer ensureWritable(int size)
Description copied from interface:BufferEnsures 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 theBufferAllocatorthe buffer was created with. This method is the same as callingBuffer.ensureWritable(int, int, boolean)whereallowCompactionistrue.- Specified by:
ensureWritablein 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:BufferEnsures 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
allowCompactionistrue, 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 sameBufferAllocatorthat this buffer was created with. -
If
allowCompactionistrue, then the implementation may choose to do a combination of compaction and allocation.
- Specified by:
ensureWritablein 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-trueif 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:BufferReturns 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:
copyin 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, boolean readOnly)
Description copied from interface:BufferReturns 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 be read-only if, and only if, the
readOnlyargument istrue, and it will not be read-only if the argument isfalse. This is the case regardless of the read-only state of this buffer.If this buffer is read-only, and a read-only copy is requested, then implementations may use structural sharing and have both buffers backed by the same underlying memory.
- Specified by:
copyin 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.readOnly- The desiredBuffer.readOnly()state 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:BufferSplits 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:BufferSplits 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:
splitin 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:BufferDiscards the read bytes, and moves the buffer contents to the beginning of the buffer.
-
countComponents
public int countComponents()
Description copied from interface:BufferGet 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:
countComponentsin interfaceBuffer- Returns:
- The number of components in this buffer.
-
countReadableComponents
public int countReadableComponents()
Description copied from interface:BufferGet 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:
countReadableComponentsin interfaceBuffer- Returns:
- The number of readable components in this buffer.
-
countWritableComponents
public int countWritableComponents()
Description copied from interface:BufferGet 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:
countWritableComponentsin 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:BufferProcesses 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
ReadableComponentobject 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
ReadableComponentinstance 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
ByteBufferinstances 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.readSplit(int),Buffer.writeSplit(int),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:
forEachReadablein 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
-
forEachReadable
public <T extends ReadableComponent & ComponentIterator.Next> ComponentIterator<T> forEachReadable()
Description copied from interface:BufferCreate a component iterator for all readable components in this buffer.Unlike the
Buffer.forEachReadable(int, ReadableComponentProcessor)method, this API permits external iteration of the components, while at the same time protecting the life-cycle of the buffer.The typical code pattern for using this API looks like the following:
Note the use of thetry (var iteration = buffer.forEachReadable()) { for (var c = iteration.first(); c != null; c = c.next()) { ByteBuffer componentBuffer = c.readableBuffer(); // ... } }varkeyword for local variables, which are required for correctly expressing the generic types used in the iteration. Following this code pattern will ensure that the components, and their parent buffer, will be correctly life-cycled.Note that the
ReadableComponentinstances exposed by the iterator could be reused for multiple calls, so the data must be extracted from the component in the context of the iteration.The
ByteBufferinstances 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.readSplit(int),Buffer.writeSplit(int),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:
forEachReadablein interfaceBuffer- Type Parameters:
T- An intersection type that presents both theReadableComponentinterface, and the ability to progress the iteration via theComponentIterator.Next.next()method.- Returns:
- A component iterator of readable components.
-
forEachWritable
public <E extends Exception> int forEachWritable(int initialIndex, WritableComponentProcessor<E> processor) throws E extends Exception
Description copied from interface:BufferProcess 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
WritableComponentobject 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 processormay 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
WritableComponentinstance 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
ByteBufferinstances 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.readSplit(int),Buffer.writeSplit(int),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:
forEachWritablein 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
-
forEachWritable
public <T extends WritableComponent & ComponentIterator.Next> ComponentIterator<T> forEachWritable()
Description copied from interface:BufferCreate a component iterator for all writable components in this buffer.Unlike the
Buffer.forEachWritable(int, WritableComponentProcessor)method, this API permits external iteration of the components, while at the same time protecting the life-cycle of the buffer.The typical code pattern for using this API looks like the following:
Note the use of thetry (var iteration = buffer.forEachWritable()) { for (var c = iteration.first(); c != null; c = c.next()) { ByteBuffer componentBuffer = c.writableBuffer(); // ... } }varkeyword for local variables, which are required for correctly expressing the generic types used in the iteration. Following this code pattern will ensure that the components, and their parent buffer, will be correctly life-cycled.Note that the
WritableComponentinstances exposed by the iterator could be reused for multiple calls, so the data must be extracted from the component in the context of the iteration.The
ByteBufferinstances 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.readSplit(int),Buffer.writeSplit(int),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 beyond the respective array offset and length, or buffer position and limit. 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:
forEachWritablein interfaceBuffer- Type Parameters:
T- An intersection type that presents both theReadableComponentinterface, and the ability to progress the iteration via theComponentIterator.Next.next()method.- Returns:
- A component iterator of readable components.
-
readByte
public byte readByte()
Description copied from interface:BufferAccessorRead 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_ENDIANbyte order.- Specified by:
readBytein interfaceBufferAccessor- Returns:
- The byte value at the current reader offset.
-
getByte
public byte getByte(int roff)
Description copied from interface:BufferAccessorGet 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_ENDIANbyte order.- Specified by:
getBytein 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:BufferAccessorRead 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_ENDIANbyte order.- Specified by:
readUnsignedBytein interfaceBufferAccessor- Returns:
- The unsigned byte value at the current reader offset.
-
getUnsignedByte
public int getUnsignedByte(int roff)
Description copied from interface:BufferAccessorGet 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_ENDIANbyte order.- Specified by:
getUnsignedBytein 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:BufferAccessorWrite 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_ENDIANbyte order.- Specified by:
writeBytein interfaceBufferAccessor- Parameters:
value- The byte value to write.- Returns:
- This Buffer.
-
setByte
public Buffer setByte(int woff, byte value)
Description copied from interface:BufferAccessorSet 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_ENDIANbyte order.- Specified by:
setBytein 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:BufferAccessorWrite 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_ENDIANbyte order.- Specified by:
writeUnsignedBytein interfaceBufferAccessor- Parameters:
value- The int value to write.- Returns:
- This Buffer.
-
setUnsignedByte
public Buffer setUnsignedByte(int woff, int value)
Description copied from interface:BufferAccessorSet 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_ENDIANbyte order.- Specified by:
setUnsignedBytein 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:BufferAccessorRead 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_ENDIANbyte order.- Specified by:
readCharin interfaceBufferAccessor- Returns:
- The char value at the current reader offset.
-
getChar
public char getChar(int roff)
Description copied from interface:BufferAccessorGet 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_ENDIANbyte order.- Specified by:
getCharin 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:BufferAccessorWrite 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_ENDIANbyte order.- Specified by:
writeCharin interfaceBufferAccessor- Parameters:
value- The char value to write.- Returns:
- This Buffer.
-
setChar
public Buffer setChar(int woff, char value)
Description copied from interface:BufferAccessorSet 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_ENDIANbyte order.- Specified by:
setCharin 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:BufferAccessorRead 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_ENDIANbyte order.- Specified by:
readShortin interfaceBufferAccessor- Returns:
- The short value at the current reader offset.
-
getShort
public short getShort(int roff)
Description copied from interface:BufferAccessorGet 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_ENDIANbyte order.- Specified by:
getShortin 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:BufferAccessorRead 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_ENDIANbyte order.- Specified by:
readUnsignedShortin interfaceBufferAccessor- Returns:
- The unsigned short value at the current reader offset.
-
getUnsignedShort
public int getUnsignedShort(int roff)
Description copied from interface:BufferAccessorGet 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_ENDIANbyte order.- Specified by:
getUnsignedShortin 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:BufferAccessorWrite 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_ENDIANbyte order.- Specified by:
writeShortin interfaceBufferAccessor- Parameters:
value- The short value to write.- Returns:
- This Buffer.
-
setShort
public Buffer setShort(int woff, short value)
Description copied from interface:BufferAccessorSet 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_ENDIANbyte order.- Specified by:
setShortin 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:BufferAccessorWrite 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_ENDIANbyte order.- Specified by:
writeUnsignedShortin interfaceBufferAccessor- Parameters:
value- The int value to write.- Returns:
- This Buffer.
-
setUnsignedShort
public Buffer setUnsignedShort(int woff, int value)
Description copied from interface:BufferAccessorSet 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_ENDIANbyte order.- Specified by:
setUnsignedShortin 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:BufferAccessorRead 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_ENDIANbyte order.- Specified by:
readMediumin interfaceBufferAccessor- Returns:
- The int value at the current reader offset.
-
getMedium
public int getMedium(int roff)
Description copied from interface:BufferAccessorGet 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_ENDIANbyte order.- Specified by:
getMediumin 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:BufferAccessorRead 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_ENDIANbyte order.- Specified by:
readUnsignedMediumin interfaceBufferAccessor- Returns:
- The unsigned int value at the current reader offset.
-
getUnsignedMedium
public int getUnsignedMedium(int roff)
Description copied from interface:BufferAccessorGet 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_ENDIANbyte order.- Specified by:
getUnsignedMediumin 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:BufferAccessorWrite 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_ENDIANbyte order.- Specified by:
writeMediumin interfaceBufferAccessor- Parameters:
value- The int value to write.- Returns:
- This Buffer.
-
setMedium
public Buffer setMedium(int woff, int value)
Description copied from interface:BufferAccessorSet 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_ENDIANbyte order.- Specified by:
setMediumin 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:BufferAccessorWrite 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_ENDIANbyte order.- Specified by:
writeUnsignedMediumin interfaceBufferAccessor- Parameters:
value- The int value to write.- Returns:
- This Buffer.
-
setUnsignedMedium
public Buffer setUnsignedMedium(int woff, int value)
Description copied from interface:BufferAccessorSet 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_ENDIANbyte order.- Specified by:
setUnsignedMediumin 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:BufferAccessorRead 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_ENDIANbyte order.- Specified by:
readIntin interfaceBufferAccessor- Returns:
- The int value at the current reader offset.
-
getInt
public int getInt(int roff)
Description copied from interface:BufferAccessorGet 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_ENDIANbyte order.- Specified by:
getIntin 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:BufferAccessorRead 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_ENDIANbyte order.- Specified by:
readUnsignedIntin interfaceBufferAccessor- Returns:
- The unsigned int value at the current reader offset.
-
getUnsignedInt
public long getUnsignedInt(int roff)
Description copied from interface:BufferAccessorGet 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_ENDIANbyte order.- Specified by:
getUnsignedIntin 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:BufferAccessorWrite 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_ENDIANbyte order.- Specified by:
writeIntin interfaceBufferAccessor- Parameters:
value- The int value to write.- Returns:
- This Buffer.
-
setInt
public Buffer setInt(int woff, int value)
Description copied from interface:BufferAccessorSet 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_ENDIANbyte order.- Specified by:
setIntin 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:BufferAccessorWrite 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_ENDIANbyte order.- Specified by:
writeUnsignedIntin interfaceBufferAccessor- Parameters:
value- The long value to write.- Returns:
- This Buffer.
-
setUnsignedInt
public Buffer setUnsignedInt(int woff, long value)
Description copied from interface:BufferAccessorSet 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_ENDIANbyte order.- Specified by:
setUnsignedIntin 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:BufferAccessorRead 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_ENDIANbyte order.- Specified by:
readFloatin interfaceBufferAccessor- Returns:
- The float value at the current reader offset.
-
getFloat
public float getFloat(int roff)
Description copied from interface:BufferAccessorGet 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_ENDIANbyte order.- Specified by:
getFloatin 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:BufferAccessorWrite 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_ENDIANbyte order.- Specified by:
writeFloatin interfaceBufferAccessor- Parameters:
value- The float value to write.- Returns:
- This Buffer.
-
setFloat
public Buffer setFloat(int woff, float value)
Description copied from interface:BufferAccessorSet 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_ENDIANbyte order.- Specified by:
setFloatin 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:BufferAccessorRead 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_ENDIANbyte order.- Specified by:
readLongin interfaceBufferAccessor- Returns:
- The long value at the current reader offset.
-
getLong
public long getLong(int roff)
Description copied from interface:BufferAccessorGet 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_ENDIANbyte order.- Specified by:
getLongin 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:BufferAccessorWrite 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_ENDIANbyte order.- Specified by:
writeLongin interfaceBufferAccessor- Parameters:
value- The long value to write.- Returns:
- This Buffer.
-
setLong
public Buffer setLong(int woff, long value)
Description copied from interface:BufferAccessorSet 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_ENDIANbyte order.- Specified by:
setLongin 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:BufferAccessorRead 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_ENDIANbyte order.- Specified by:
readDoublein interfaceBufferAccessor- Returns:
- The double value at the current reader offset.
-
getDouble
public double getDouble(int roff)
Description copied from interface:BufferAccessorGet 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_ENDIANbyte order.- Specified by:
getDoublein 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:BufferAccessorWrite 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_ENDIANbyte order.- Specified by:
writeDoublein interfaceBufferAccessor- Parameters:
value- The double value to write.- Returns:
- This Buffer.
-
setDouble
public Buffer setDouble(int woff, double value)
Description copied from interface:BufferAccessorSet 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_ENDIANbyte order.- Specified by:
setDoublein interfaceBufferAccessor- Parameters:
woff- The write offset, an absolute offset into this buffer to write to.value- The double value to write.- Returns:
- This Buffer.
-
writeCharSequence
public Buffer writeCharSequence(CharSequence source, Charset charset)
Description copied from interface:BufferWrites into this buffer, all the bytes from the givensourceusing the passedcharset. This updates the write offset of this buffer.- Specified by:
writeCharSequencein interfaceBuffer- Parameters:
source-CharSequenceto read from.charset-Charsetto use for writing.- Returns:
- This buffer.
-
readCharSequence
public CharSequence readCharSequence(int length, Charset charset)
Description copied from interface:BufferReads aCharSequenceof the passedlengthusing the passedCharset. This updates the Buffer.readerOffset() reader offset} of this buffer.- Specified by:
readCharSequencein interfaceBuffer- Parameters:
length- ofCharSequenceto read.charset- of the bytes to be read.- Returns:
CharSequenceread from this buffer.
-
writeBytes
public Buffer writeBytes(byte[] source, int srcPos, int length)
Description copied from interface:BufferWrites into this buffer, the given number of bytes from the byte array. This updates the write offset of this buffer by the length argument.- Specified by:
writeBytesin interfaceBuffer- Parameters:
source- The byte array to read from.srcPos- Position in thesourcefrom where bytes should be written to this buffer.length- The number of bytes to copy.- Returns:
- This buffer.
-
readBytes
public Buffer readBytes(byte[] destination, int destPos, int length)
Description copied from interface:BufferRead from this buffer, into the destination array, the given number of bytes. This updates the read offset of this buffer by the length argument.
-
copy
public Buffer copy(int offset, int length)
Description copied from interface:BufferReturns 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. This has the same effect as calling
Buffer.copy(int, int, boolean)with afalseread-only argument.- Specified by:
copyin 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.
-
readSplit
public Buffer readSplit(int length)
Description copied from interface:BufferSplits the buffer into two, atlengthnumber of bytes from the current Buffer.readerOffset() reader offset} position.The region of this buffer that contain the previously read and readable bytes till the
readerOffset() + lengthposition, 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 change its
Buffer.readerOffset()toreaderOffset() + length, and have itsBuffer.writerOffset()andBuffer.capacity()both set to thereaderOffset() + lengthposition.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, read offset will become zero and relative position of write offset will be preserved from the provided
readerOffset() + lengthposition, 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, where offset = readerOffset() + length: +------------------------------------------+ 0| |r/o offset |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.
-
writeSplit
public Buffer writeSplit(int length)
Description copied from interface:BufferSplits the buffer into two, atlengthnumber of bytes from the current Buffer.writerOffset() writer offset} position.The region of this buffer that contain the previously read and readable bytes till the
writerOffset() + lengthposition, 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 change its
Buffer.writerOffset()towriterOffset() + length, and have itsBuffer.writerOffset()andBuffer.capacity()both set to thewriterOffset() + length.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, read offset will become zero and relative position of write offset will be preserved from the provided
writerOffset() + lengthposition, 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, where offset = writerOffset() + length: +------------------------------------------+ 0| |r/o |w/o offset |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.
- Specified by:
writeSplitin interfaceBuffer- Returns:
- A new buffer with independent and exclusive ownership over the previously read and readable bytes from this buffer.
-
readBoolean
public boolean readBoolean()
Description copied from interface:BufferAccessorRead the boolean value at the currentBuffer.readerOffset(), and increases the reader offset byByte.BYTES. A boolean gets read as a byte from this buffer. All byte values which are not equal to zero are considered as the boolean valuetrue, zero representsfalse.- Specified by:
readBooleanin interfaceBufferAccessor- Returns:
- The boolean value at the current reader offset.
-
getBoolean
public boolean getBoolean(int roff)
Description copied from interface:BufferAccessorGet the boolean value at the given reader offset. TheBuffer.readerOffset()is not modified. A boolean gets read as a byte from this buffer. All byte values which are not equal to zero are considered as the boolean valuetrue, zero representsfalse.- Specified by:
getBooleanin interfaceBufferAccessor- Parameters:
roff- The read offset, an absolute offset into this buffer, to read from.- Returns:
- The boolean value at the given offset.
-
writeBoolean
public Buffer writeBoolean(boolean value)
Description copied from interface:BufferAccessorWrite the given boolean value at the currentBuffer.writerOffset(), and increase the writer offset byByte.BYTES. A boolean gets written as a byte to this buffer. All byte values which are not equal to zero are considered as the boolean valuetrue, zero representsfalse.- Specified by:
writeBooleanin interfaceBufferAccessor- Parameters:
value- The boolean value to write.- Returns:
- This Buffer.
-
setBoolean
public Buffer setBoolean(int woff, boolean value)
Description copied from interface:BufferAccessorSet the given boolean value at the given write offset. TheBuffer.writerOffset()is not modified. A boolean gets written as a byte to this buffer. All byte values which are not equal to zero are considered as the boolean valuetrue, zero representsfalse.- Specified by:
setBooleanin interfaceBufferAccessor- Parameters:
woff- The write offset, an absolute offset into this buffer to write to.value- The boolean value to write.- Returns:
- This Buffer.
-
writeBytes
public Buffer writeBytes(ByteBuffer source)
Description copied from interface:BufferWrites into this buffer from the sourceByteBuffer. This updates the write offset of this buffer and also the position of the sourceByteBuffer.Note: the behaviour is undefined if the given
ByteBufferis an alias for the memory in this buffer.- Specified by:
writeBytesin interfaceBuffer- Parameters:
source- TheByteBufferto read from.- Returns:
- This buffer.
-
readBytes
public Buffer readBytes(ByteBuffer destination)
Description copied from interface:BufferRead from this buffer, into the destinationByteBufferThis updates the read offset of this buffer and also the position of the destinationByteBuffer.Note: the behaviour is undefined if the given
ByteBufferis an alias for the memory in this buffer.- Specified by:
readBytesin interfaceBuffer- Parameters:
destination- TheByteBufferto write into.- Returns:
- This buffer.
-
copy
public Buffer copy(boolean readOnly)
Description copied from interface:BufferReturns a copy of this buffer's readable bytes, with the given read-only setting. 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 be read-only if, and only if, the
readOnlyargument istrue, and it will not be read-only if the argument isfalse. This is the case regardless of the read-only state of this buffer.If this buffer is read-only, and a read-only copy is requested, then implementations may use structural sharing and have both buffers backed by the same underlying memory.
- Specified by:
copyin interfaceBuffer- Parameters:
readOnly- The desiredBuffer.readOnly()state 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.
-
send
public io.netty5.util.Send<Buffer> send()
- Specified by:
sendin interfaceio.netty5.util.Resource<Buffer>
-
close
public void close()
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceio.netty5.util.Resource<Buffer>
-
isAccessible
public boolean isAccessible()
- Specified by:
isAccessiblein interfaceio.netty5.util.Resource<Buffer>
-
touch
public Buffer touch(Object hint)
- Specified by:
touchin interfaceio.netty5.util.Resource<Buffer>
-
toString
public String toString(Charset charset)
Description copied from interface:BufferDecodes 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.
-
-