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:
BufferAllocator#compose(Iterable) creates a composite buffer from the buffers that are sent to it via
the passed in send objects. Since Send#receive() transfers ownership, the resulting composite buffer
will have ownership, because it is guaranteed that there are no other references to its constituent buffers.
BufferAllocator#compose(Send) creates a composite buffer with a single component.
Since Send#receive() transfers ownership, the resulting composite buffer
will have ownership, because it is guaranteed that there are no other references to its constituent buffer.
BufferAllocator#compose() creates an empty, zero capacity, composite buffer. Such empty buffers may
change their read-only states when they gain their first component.
ensureWritable(int),
or with externally allocated buffers, using extendWith(Send).
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.
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.
| Modifier and Type | Method and Description |
|---|---|
| public CompositeBuffer | compact()
Redeclares io. |
| public static CompositeBuffer | Returns: A composite buffer that has no components, and has a capacity of zero.The allocator for the composite buffer. This allocator will be used e.g. to service
allocator)ensureWritable(int) calls.Create an empty composite buffer, that has no components. |
| public default CompositeBuffer | copy()
Overrides default io. |
| 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. |
| 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)readOnly() state of the returned buffer.Redeclares io. |
| public Buffer[] | Returns: An array of the constituent buffer components.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. |
| 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 allowCompaction)Redeclares io. |
| public CompositeBuffer | Returns: This composite buffer instance.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. |
| public CompositeBuffer | implicitCapacityLimit(int
The maximum size this buffers capacity will implicitly grow to via limit)write* methods.Redeclares io. |
| public static boolean | Returns: true if the given buffer was created with BufferAllocator#compose(),
BufferAllocator#compose(Send) or BufferAllocator#compose(Iterable), false otherwise.The buffer to check. composite)Check if the given buffer is a composite buffer or not. |
| public CompositeBuffer | |
| public default CompositeBuffer | readBytes(byte[]
The byte array to write into. destination, int Position in the destPos, int destination to where bytes should be written from this buffer.The number of bytes to copy. length)Overrides default io. |
| public default CompositeBuffer | readBytes(ByteBuffer
The destination)ByteBuffer to write into.Overrides default io. 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. |
| public default CompositeBuffer | resetOffsets()
Overrides default io. |
| 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. |
| 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. |
| 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. |
| 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. |
| 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. |
| 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. |
| 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. |
| 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. |
| 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. |
| 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. |
| 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. |
| 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. |
| 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. |
| public default CompositeBuffer | skipReadableBytes(int
to accumulate. delta)Overrides default io. |
| public default CompositeBuffer | skipWritableBytes(int
to accumulate. delta)Overrides default io. |
| public default CompositeBuffer | split()
Overrides default io. |
| 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. 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.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.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. Buffer#writerOffset(),
and increase the writer offset by Byte#BYTES.
|
| public CompositeBuffer | writeByte(byte
The byte value to write. value)Redeclares io. Buffer#writerOffset(),
and increase the writer offset by Byte#BYTES.
|
| public default CompositeBuffer | writeBytes(Buffer
The buffer to read from. source)Overrides default io. |
| public default CompositeBuffer | writeBytes(byte[]
The byte array to read from. source)Overrides default io. |
| public default CompositeBuffer | writeBytes(byte[]
The byte array to read from. source, int Position in the srcPos, int source from where bytes should be written to this buffer.The number of bytes to copy. length)Overrides default io. |
| public default CompositeBuffer | writeBytes(ByteBuffer
The source)ByteBuffer to read from.Overrides default io. ByteBuffer.
|
| public CompositeBuffer | writeChar(char
The char value to write. value)Redeclares io. Buffer#writerOffset(),
and increase the writer offset by 2.
|
| public default CompositeBuffer | writeCharSequence(CharSequence
CharSequence to read from.Charset to use for writing.Overrides default io. source using the passed charset.
|
| public CompositeBuffer | writeDouble(double
The double value to write. value)Redeclares io. Buffer#writerOffset(),
and increase the writer offset by Double#BYTES.
|
| public CompositeBuffer | writeFloat(float
The float value to write. value)Redeclares io. Buffer#writerOffset(),
and increase the writer offset by Float#BYTES.
|
| public CompositeBuffer | writeInt(int
The int value to write. value)Redeclares io. Buffer#writerOffset(),
and increase the writer offset by Integer#BYTES.
|
| public CompositeBuffer | writeLong(long
The long value to write. value)Redeclares io. Buffer#writerOffset(),
and increase the writer offset by Long#BYTES.
|
| public CompositeBuffer | writeMedium(int
The int value to write. value)Redeclares io. Buffer#writerOffset(),
and increase the writer offset by 3.
|
| public CompositeBuffer | writerOffset(int
The writer offset to set. offset)Redeclares io. |
| public CompositeBuffer | writeShort(short
The short value to write. value)Redeclares io. Buffer#writerOffset(),
and increase the writer offset by Short#BYTES.
|
| public CompositeBuffer | writeUnsignedByte(int
The int value to write. value)Redeclares io. Buffer#writerOffset(),
and increase the writer offset by Byte#BYTES.
|
| public CompositeBuffer | writeUnsignedInt(long
The long value to write. value)Redeclares io. Buffer#writerOffset(),
and increase the writer offset by Integer#BYTES.
|
| public CompositeBuffer | writeUnsignedMedium(int
The int value to write. value)Redeclares io. Buffer#writerOffset(),
and increase the writer offset by 3.
|
| public CompositeBuffer | writeUnsignedShort(int
The int value to write. value)Redeclares io. Buffer#writerOffset(),
and increase the writer offset by Short#BYTES.
|