Top Description Methods
io.netty5.buffer

public Interface CompositeBuffer

extends Buffer
Known Direct Implementers
io.netty5.buffer.DefaultCompositeBuffer
Imports
io.netty5.util.Resource, .Send, java.nio.ByteBuffer, java.nio.charset.Charset

The CompositeBuffer is a concrete Buffer implementation that make a number of other buffers appear as one. A composite buffer behaves the same as a normal, non-composite buffer in every way, so you normally don't need to handle them specially.

A composite buffer is constructed using one of the compose methods:

Composite buffers can later be extended with internally allocated components, with ensureWritable(int), or with externally allocated buffers, using extendWith(Send).

How buffers compose

A buffer can be thought of as having three distinct regions, in order:
  1. Memory that have been read.
  2. Memory that is readable.
  3. Memory that can be written to.
A composite buffer must present itself similarly, but may be composed of buffers where their offsets don't line up, and thus end up producing "gaps" in the composite buffer. The solution is that the composite buffer hide these gaps from view.

For example, if we compose two buffers that both have non-zero read-offset, then the composite buffer will get the read-offset of the first buffer, followed by a concatenation of the readable memory from both. Similarly, the write-offset of the composite buffer will come from the last buffer with a non-zero write-offset, and any writable memory prior to the last readable memory region will be hidden:

    First buffer                Second buffer
     +----------------------+    +--------------------+
    0|    |r/o      |w/o    |   0|    |r/o     |w/o   |
     +----+---------+-------+    +----+--------+------+
      \    \         \  ,____________/   ,___________/
       \    \         \/                /
        +----+---------+--------+------+
       0|    |r/o      :        |w/o   |  Composite buffer
        +------------------------------+
Components in the middle can have both their end-regions hidden in the same way, so only their readable memory is included in the composite buffer. Buffers that consist entirely of memory that has already been read, or memory that is writable, can also concatenate onto those regions at the ends. The final capacity of the composite buffer, will be the sum of all the visible regions.

Reads and writes to the composite buffer that modifies the read or write offsets, will also modify the relevant offsets in the constituent buffers.

Constituent buffer requirements

The buffers that are being composed must all have the same writability. Either all components must be read-only, or they must all be writable.

It is not a requirement that the buffers have the same size.

It is not a requirement that the buffers are allocated by this allocator, but if Buffer#ensureWritable(int) is called on the composed buffer, and the composed buffer needs to be expanded, then this allocator instance will be used for allocation the extra memory.

Ownership and Send

Sending a composite buffer implies sending all of its constituent buffers. For sending to be possible, both the composite buffer itself, and all of its constituent buffers, must be in a state that permits them being sent. This should be the case by default, as it shouldn't be possible to create composite buffers that can't be sent.

Method Summary

Modifier and TypeMethod and Description
public CompositeBuffer
compact()

Redeclares io.netty5.buffer.Buffer.compact.

Discards the read bytes, and moves the buffer contents to the beginning of the buffer.
public static CompositeBuffer

Returns:

A composite buffer that has no components, and has a capacity of zero.
compose
(BufferAllocator
The allocator for the composite buffer. This allocator will be used e.g. to service ensureWritable(int) calls.
allocator
)

Create an empty composite buffer, that has no components.

public default CompositeBuffer
copy()

Overrides default io.netty5.buffer.Buffer.copy.

Returns a copy of this buffer's readable bytes.
public default CompositeBuffer
copy(int
The offset where copying should start from. This is the offset of the first byte copied.
offset
,
int
The number of bytes to copy, and the capacity of the returned buffer.
length
)

Overrides default io.netty5.buffer.Buffer.copy.

Returns a copy of the given region of this buffer.
public CompositeBuffer
copy(int
The offset where copying should start from. This is the offset of the first byte copied.
offset
,
int
The number of bytes to copy, and the capacity of the returned buffer.
length
,
boolean
The desired readOnly() state of the returned buffer.
readOnly
)

Redeclares io.netty5.buffer.Buffer.copy.

Returns a copy of the given region of this buffer.
public Buffer[]

Returns:

An array of the constituent buffer components.
decomposeBuffer
()

Break a composite buffer into its constituent components.

public default CompositeBuffer
ensureWritable(int
The requested number of bytes of space that should be available for writing.
size
)

Overrides default io.netty5.buffer.Buffer.ensureWritable.

Ensures that this buffer has at least the given number of bytes of available space for writing.
public CompositeBuffer
ensureWritable(int
The requested number of bytes of space that should be available for writing.
size
,
int
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.
minimumGrowth
,
boolean
true if the method is allowed to modify the reader offset and writer offset, otherwise false.
allowCompaction
)

Redeclares io.netty5.buffer.Buffer.ensureWritable.

Ensures that this buffer has at least the given number of bytes of available space for writing.
public CompositeBuffer

Returns:

This composite buffer instance.
extendWith
(Send<Buffer>
The buffer to extend the composite buffer with.
extension
)

Extend this composite buffer with the given extension buffer.

public CompositeBuffer
fill(byte
The byte value to write at every offset in the buffer.
value
)

Redeclares io.netty5.buffer.Buffer.fill.

Fills the buffer with the given byte value.
public CompositeBuffer
implicitCapacityLimit(int
The maximum size this buffers capacity will implicitly grow to via write* methods.
limit
)

Redeclares io.netty5.buffer.Buffer.implicitCapacityLimit.

Set an upper limit to the implicit capacity growth.
public static boolean

Returns:

true if the given buffer was created with BufferAllocator#compose(), BufferAllocator#compose(Send) or BufferAllocator#compose(Iterable), false otherwise.
isComposite
(Buffer
The buffer to check.
composite
)

Check if the given buffer is a composite buffer or not.

public CompositeBuffer
makeReadOnly()

Redeclares io.netty5.buffer.Buffer.makeReadOnly.

Makes this buffer read-only.
public default CompositeBuffer
readBytes(byte[]
The byte array to write into.
destination
,
int
Position in the destination to where bytes should be written from this buffer.
destPos
,
int
The number of bytes to copy.
length
)

Overrides default io.netty5.buffer.Buffer.readBytes.

Read from this buffer, into the destination array, the given number of bytes.
public default CompositeBuffer
readBytes(ByteBuffer
The ByteBuffer to write into.
destination
)

Overrides default io.netty5.buffer.Buffer.readBytes.

Read from this buffer, into the destination ByteBuffer This updates the read offset of this buffer and also the position of the destination ByteBuffer.
public CompositeBuffer
readerOffset(int
The reader offset to set.
offset
)

Redeclares io.netty5.buffer.Buffer.readerOffset.

Set the reader offset.
public default CompositeBuffer
resetOffsets()

Overrides default io.netty5.buffer.Buffer.resetOffsets.

Resets the read offset and the write offset on this buffer to zero, and return this buffer.
public default CompositeBuffer
setBoolean(int
The write offset, an absolute offset into this buffer to write to.
woff
,
boolean
The boolean value to write.
value
)

Overrides default io.netty5.buffer.BufferAccessor.setBoolean.

Set the given boolean value at the given write offset.
public CompositeBuffer
setByte(int
The write offset, an absolute offset into this buffer to write to.
woff
,
byte
The byte value to write.
value
)

Redeclares io.netty5.buffer.BufferAccessor.setByte.

Set the given byte value at the given write offset.
public CompositeBuffer
setChar(int
The write offset, an absolute offset into this buffer to write to.
woff
,
char
The char value to write.
value
)

Redeclares io.netty5.buffer.BufferAccessor.setChar.

Set the given char value at the given write offset.
public CompositeBuffer
setDouble(int
The write offset, an absolute offset into this buffer to write to.
woff
,
double
The double value to write.
value
)

Redeclares io.netty5.buffer.BufferAccessor.setDouble.

Set the given double value at the given write offset.
public CompositeBuffer
setFloat(int
The write offset, an absolute offset into this buffer to write to.
woff
,
float
The float value to write.
value
)

Redeclares io.netty5.buffer.BufferAccessor.setFloat.

Set the given float value at the given write offset.
public CompositeBuffer
setInt(int
The write offset, an absolute offset into this buffer to write to.
woff
,
int
The int value to write.
value
)

Redeclares io.netty5.buffer.BufferAccessor.setInt.

Set the given int value at the given write offset.
public CompositeBuffer
setLong(int
The write offset, an absolute offset into this buffer to write to.
woff
,
long
The long value to write.
value
)

Redeclares io.netty5.buffer.BufferAccessor.setLong.

Set the given long value at the given write offset.
public CompositeBuffer
setMedium(int
The write offset, an absolute offset into this buffer to write to.
woff
,
int
The int value to write.
value
)

Redeclares io.netty5.buffer.BufferAccessor.setMedium.

Set the given int value at the given write offset.
public CompositeBuffer
setShort(int
The write offset, an absolute offset into this buffer to write to.
woff
,
short
The short value to write.
value
)

Redeclares io.netty5.buffer.BufferAccessor.setShort.

Set the given short value at the given write offset.
public CompositeBuffer
setUnsignedByte(int
The write offset, an absolute offset into this buffer to write to.
woff
,
int
The int value to write.
value
)

Redeclares io.netty5.buffer.BufferAccessor.setUnsignedByte.

Set the given unsigned byte value at the given write offset.
public CompositeBuffer
setUnsignedInt(int
The write offset, an absolute offset into this buffer to write to.
woff
,
long
The long value to write.
value
)

Redeclares io.netty5.buffer.BufferAccessor.setUnsignedInt.

Set the given unsigned int value at the given write offset.
public CompositeBuffer
setUnsignedMedium(int
The write offset, an absolute offset into this buffer to write to.
woff
,
int
The int value to write.
value
)

Redeclares io.netty5.buffer.BufferAccessor.setUnsignedMedium.

Set the given unsigned int value at the given write offset.
public CompositeBuffer
setUnsignedShort(int
The write offset, an absolute offset into this buffer to write to.
woff
,
int
The int value to write.
value
)

Redeclares io.netty5.buffer.BufferAccessor.setUnsignedShort.

Set the given unsigned short value at the given write offset.
public default CompositeBuffer
skipReadableBytes(int
to accumulate.
delta
)

Overrides default io.netty5.buffer.Buffer.skipReadableBytes.

Move the reader offset forward by the given delta.
public default CompositeBuffer
skipWritableBytes(int
to accumulate.
delta
)

Overrides default io.netty5.buffer.Buffer.skipWritableBytes.

Move the writer offset to ahead by the given delta.
public default CompositeBuffer
split()

Overrides default io.netty5.buffer.Buffer.split.

Splits the buffer into two, at the write offset position.
public CompositeBuffer
split(int
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.
splitOffset
)

Redeclares io.netty5.buffer.Buffer.split.

Splits the buffer into two, at the given splitOffset.
public CompositeBuffer

Returns:

A new buffer with independent and exclusive ownership over the bytes from the beginning to a component boundary greater than or equal to the given offset of this buffer.
splitComponentsCeil
(int
The minimum split offset. The real split offset will be at a component boundary that is greater than or equal to this offset.
splitOffset
)

Split this buffer at a component boundary that is greater than or equal to the given offset.

public CompositeBuffer

Returns:

A new buffer with independent and exclusive ownership over the bytes from the beginning to a component boundary less than or equal to the given offset of this buffer.
splitComponentsFloor
(int
The maximum split offset. The real split offset will be at a component boundary that is less than or equal to this offset.
splitOffset
)

Split this buffer at a component boundary that is less than or equal to the given offset.

public default CompositeBuffer
writeBoolean(boolean
The boolean value to write.
value
)

Overrides default io.netty5.buffer.BufferAccessor.writeBoolean.

Write the given boolean value at the current Buffer#writerOffset(), and increase the writer offset by Byte#BYTES.
public CompositeBuffer
writeByte(byte
The byte value to write.
value
)

Redeclares io.netty5.buffer.BufferAccessor.writeByte.

Write the given byte value at the current Buffer#writerOffset(), and increase the writer offset by Byte#BYTES.
public default CompositeBuffer
writeBytes(Buffer
The buffer to read from.
source
)

Overrides default io.netty5.buffer.Buffer.writeBytes.

Writes into this buffer, all the readable bytes from the given buffer.
public default CompositeBuffer
writeBytes(byte[]
The byte array to read from.
source
)

Overrides default io.netty5.buffer.Buffer.writeBytes.

Writes into this buffer, all the bytes from the given byte array.
public default CompositeBuffer
writeBytes(byte[]
The byte array to read from.
source
,
int
Position in the source from where bytes should be written to this buffer.
srcPos
,
int
The number of bytes to copy.
length
)

Overrides default io.netty5.buffer.Buffer.writeBytes.

Writes into this buffer, the given number of bytes from the byte array.
public default CompositeBuffer
writeBytes(ByteBuffer
The ByteBuffer to read from.
source
)

Overrides default io.netty5.buffer.Buffer.writeBytes.

Writes into this buffer from the source ByteBuffer.
public CompositeBuffer
writeChar(char
The char value to write.
value
)

Redeclares io.netty5.buffer.BufferAccessor.writeChar.

Write the given char value at the current Buffer#writerOffset(), and increase the writer offset by 2.
public default CompositeBuffer
writeCharSequence(CharSequence
CharSequence to read from.
source
,
Charset
Charset to use for writing.
charset
)

Overrides default io.netty5.buffer.Buffer.writeCharSequence.

Writes into this buffer, all the bytes from the given source using the passed charset.
public CompositeBuffer
writeDouble(double
The double value to write.
value
)

Redeclares io.netty5.buffer.BufferAccessor.writeDouble.

Write the given double value at the current Buffer#writerOffset(), and increase the writer offset by Double#BYTES.
public CompositeBuffer
writeFloat(float
The float value to write.
value
)

Redeclares io.netty5.buffer.BufferAccessor.writeFloat.

Write the given float value at the current Buffer#writerOffset(), and increase the writer offset by Float#BYTES.
public CompositeBuffer
writeInt(int
The int value to write.
value
)

Redeclares io.netty5.buffer.BufferAccessor.writeInt.

Write the given int value at the current Buffer#writerOffset(), and increase the writer offset by Integer#BYTES.
public CompositeBuffer
writeLong(long
The long value to write.
value
)

Redeclares io.netty5.buffer.BufferAccessor.writeLong.

Write the given long value at the current Buffer#writerOffset(), and increase the writer offset by Long#BYTES.
public CompositeBuffer
writeMedium(int
The int value to write.
value
)

Redeclares io.netty5.buffer.BufferAccessor.writeMedium.

Write the given int value at the current Buffer#writerOffset(), and increase the writer offset by 3.
public CompositeBuffer
writerOffset(int
The writer offset to set.
offset
)

Redeclares io.netty5.buffer.Buffer.writerOffset.

Set the writer offset.
public CompositeBuffer
writeShort(short
The short value to write.
value
)

Redeclares io.netty5.buffer.BufferAccessor.writeShort.

Write the given short value at the current Buffer#writerOffset(), and increase the writer offset by Short#BYTES.
public CompositeBuffer
writeUnsignedByte(int
The int value to write.
value
)

Redeclares io.netty5.buffer.BufferAccessor.writeUnsignedByte.

Write the given unsigned byte value at the current Buffer#writerOffset(), and increase the writer offset by Byte#BYTES.
public CompositeBuffer
writeUnsignedInt(long
The long value to write.
value
)

Redeclares io.netty5.buffer.BufferAccessor.writeUnsignedInt.

Write the given unsigned int value at the current Buffer#writerOffset(), and increase the writer offset by Integer#BYTES.
public CompositeBuffer
writeUnsignedMedium(int
The int value to write.
value
)

Redeclares io.netty5.buffer.BufferAccessor.writeUnsignedMedium.

Write the given unsigned int value at the current Buffer#writerOffset(), and increase the writer offset by 3.
public CompositeBuffer
writeUnsignedShort(int
The int value to write.
value
)

Redeclares io.netty5.buffer.BufferAccessor.writeUnsignedShort.

Write the given unsigned short value at the current Buffer#writerOffset(), and increase the writer offset by Short#BYTES.
Inherited from io.netty5.buffer.Buffer:
bytesBeforebytesBeforecapacitycopycopyIntocopyIntocopyIntocountComponentscountReadableComponentscountWritableComponentsforEachComponentimplicitCapacityLimitisDirectopenCursoropenCursoropenReverseCursoropenReverseCursorreadableBytesreadCharSequencereaderOffsetreadOnlyreadSplittoStringtransferFromtransferFromtransferTowritableByteswriterOffsetwriteSplit