Interface ProtonCompositeBuffer
- All Superinterfaces:
AutoCloseable
,Comparable<ProtonBuffer>
,ProtonBuffer
,ProtonBufferAccessors
,Resource<ProtonBuffer>
- All Known Implementing Classes:
ProtonCompositeBufferImpl
-
Method Summary
Modifier and TypeMethodDescriptiondefault ProtonCompositeBuffer
advanceReadOffset
(int length) Adjusts the currentProtonBuffer.getReadOffset()
of this buffer by the specifiedlength
.default ProtonCompositeBuffer
advanceWriteOffset
(int length) Adjusts the currentProtonBuffer.getWriteOffset()
of this buffer by the specifiedlength
.append
(ProtonBuffer buffer) Appends the given buffer to this composite buffer if all the constraints on buffer composites are met, otherwise thrown an exception.compact()
Moves the readable portion of the buffer to the beginning of the underlying buffer storage and possibly makes additional bytes available for writes before a buffer expansion would occur via anProtonBuffer.ensureWritable(int)
call.Converts this buffer instance to a read-only buffer, any write operation that is performed on this buffer following this call will fail.default ProtonCompositeBuffer
copy()
Create a deep copy of the readable bytes of this ProtonBuffer, the returned buffer can be modified without affecting the contents or position markers of this instance.default ProtonCompositeBuffer
copy
(boolean readOnly) Returns a copy of this buffer's readable bytes and sets the read-only state of the returned buffer based on the value of the read-only flag.default ProtonCompositeBuffer
copy
(int index, int length) Returns a copy of this buffer's sub-region.copy
(int index, int length, boolean readOnly) Returns a copy of this buffer's sub-region.static ProtonCompositeBuffer
create
(ProtonBufferAllocator allocator) Create an empty composite buffer that will use the provided allocator to create new buffer capacity if writes are performed and insufficient space remains (unless the capacity limit is reached).static ProtonCompositeBuffer
create
(ProtonBufferAllocator allocator, ProtonBuffer buffer) Create an composite buffer with the given buffer instance as the initial buffer payload.static ProtonCompositeBuffer
create
(ProtonBufferAllocator allocator, ProtonBuffer[] buffers) Create an composite buffer with the given array of buffers as the initial buffer payload.Splits the composite buffer up into a collection of buffers that comprise it and leaves this buffer in what is effectively a closed state.default ProtonCompositeBuffer
ensureWritable
(int amount) Ensures that the requested number of bytes is available for write operations in the current buffer, growing the buffer if needed to meet the requested writable capacity.ensureWritable
(int size, int minimumGrowth, boolean allowCompaction) Ensures that the requested number of bytes is available for write operations in the current buffer, growing the buffer if needed to meet the requested writable capacity.fill
(byte value) Assigns the given value to every byte in the buffer without respect for the buffer read or write offsets.implicitGrowthLimit
(int limit) Configures the limit assigned to this buffer if one was set which controls how large the capacity of the buffer can grow implicitly via write calls.static boolean
isComposite
(ProtonBuffer buffer) Checks if the given buffer is an composite buffer instance or not.default ProtonCompositeBuffer
readBytes
(byte[] destination, int offset, int length) Read from this buffer, into the destination array, the given number of bytes.default ProtonCompositeBuffer
readBytes
(ByteBuffer destination) Read from this buffer, into the destinationByteBuffer
This updates the read offset of this buffer and also the position of the destinationByteBuffer
.default ProtonCompositeBuffer
readSplit
(int length) Splits this buffer at the read offset + the length given.setReadOffset
(int value) Sets the read offset for this buffer.setWriteOffset
(int value) Sets the write offset for this buffer.default ProtonCompositeBuffer
split()
Splits this buffer at the write offset.split
(int splitOffset) Splits this buffer at the given offset.splitComponentsCeil
(int splitOffset) Split this buffer returning a composite that consists of all the buffer components up to and including the buffer that contains the split offset, no buffer components are split.splitComponentsFloor
(int splitOffset) Split this buffer returning a composite that consists of all the buffer components that come before the buffer that contains the split offset, no buffer components are split.default ProtonCompositeBuffer
writeBytes
(byte[] source) Writes into this buffer, all the bytes from the given byte array.default ProtonCompositeBuffer
writeBytes
(byte[] source, int offset, int length) Writes into this buffer, the given number of bytes from the byte array.default ProtonCompositeBuffer
writeBytes
(ByteBuffer source) Writes into this buffer from the sourceByteBuffer
.default ProtonCompositeBuffer
writeBytes
(ProtonBuffer source) Writes into this buffer, all the readable bytes from the given buffer.default ProtonCompositeBuffer
writeSplit
(int length) Splits this buffer at the write offset + the length given.Methods inherited from interface org.apache.qpid.protonj2.buffer.ProtonBuffer
bufferIterator, bufferIterator, bufferReverseIterator, bufferReverseIterator, capacity, clear, close, compareTo, componentAccessor, componentCount, copyInto, copyInto, copyInto, getReadableBytes, getReadOffset, getWritableBytes, getWriteOffset, implicitGrowthLimit, indexOf, indexOf, isClosed, isComposite, isDirect, isReadable, isReadOnly, isWritable, readableComponentCount, readCharSequence, toString, transferFrom, transferFrom, transferTo, unwrap, writableComponentCount, writeCharSequence
Methods inherited from interface org.apache.qpid.protonj2.buffer.ProtonBufferAccessors
getBoolean, getByte, getChar, getDouble, getFloat, getInt, getLong, getShort, getUnsignedByte, getUnsignedInt, getUnsignedShort, readBoolean, readByte, readChar, readDouble, readFloat, readInt, readLong, readShort, readUnsignedByte, readUnsignedInt, readUnsignedShort, setBoolean, setByte, setChar, setDouble, setFloat, setInt, setLong, setShort, setUnsignedByte, setUnsignedInt, setUnsignedShort, writeBoolean, writeByte, writeChar, writeDouble, writeFloat, writeInt, writeLong, writeShort, writeUnsignedByte, writeUnsignedInt, writeUnsignedShort
-
Method Details
-
create
Create an empty composite buffer that will use the provided allocator to create new buffer capacity if writes are performed and insufficient space remains (unless the capacity limit is reached).- Parameters:
allocator
- The allocator to use when adding new buffer capacity automatically.- Returns:
- a new empty composite buffer instance.
-
create
Create an composite buffer with the given buffer instance as the initial buffer payload. The provided buffer allocator will use the provided allocator to create new buffer capacity if writes are performed and insufficient space remains (unless the capacity limit is reached).- Parameters:
allocator
- The allocator to use when adding new buffer capacity automatically.buffer
- The initial buffer to append as the body of the returned composite buffer.- Returns:
- a new composite buffer instance that wraps the given buffer.
-
create
Create an composite buffer with the given array of buffers as the initial buffer payload. The provided buffer allocator will use the provided allocator to create new buffer capacity if writes are performed and insufficient space remains (unless the capacity limit is reached).- Parameters:
allocator
- The allocator to use when adding new buffer capacity automatically.buffers
- The initial buffers to append as the body of the returned composite buffer.- Returns:
- a new composite buffer instance that wraps the given buffers.
-
isComposite
Checks if the given buffer is an composite buffer instance or not.- Parameters:
buffer
- the buffer instance to check.- Returns:
- true if the buffer given is a composite buffer or false if not.
-
append
Appends the given buffer to this composite buffer if all the constraints on buffer composites are met, otherwise thrown an exception.- Parameters:
buffer
- The buffer to append to this composite collection of buffers.- Returns:
- this composite buffer instance.
-
decomposeBuffer
Iterable<ProtonBuffer> decomposeBuffer()Splits the composite buffer up into a collection of buffers that comprise it and leaves this buffer in what is effectively a closed state. The returned buffers are now the property of the caller who must ensure they are closed when no longer in use..- Returns:
- the collection of buffers that comprised this composite buffer.
-
splitComponentsFloor
Split this buffer returning a composite that consists of all the buffer components that come before the buffer that contains the split offset, no buffer components are split. This allows for operations such as reclaiming read bytes from a buffer to reduce overall memory use.- Parameters:
splitOffset
- The index into the buffer where the split should be performed.- Returns:
- A
ProtonCompositeBuffer
that owns all buffers that come before the buffer that holds given index.
-
splitComponentsCeil
Split this buffer returning a composite that consists of all the buffer components up to and including the buffer that contains the split offset, no buffer components are split.- Parameters:
splitOffset
- The index into the buffer where the split should be performed.- Returns:
- A
ProtonCompositeBuffer
that owns all buffers up to and including the buffer that holds given index.
-
fill
Description copied from interface:ProtonBuffer
Assigns the given value to every byte in the buffer without respect for the buffer read or write offsets.- Specified by:
fill
in interfaceProtonBuffer
- Parameters:
value
- The byte value to assign each byte in this buffer.- Returns:
- this ProtonBuffer for chaining.
-
setReadOffset
Description copied from interface:ProtonBuffer
Sets the read offset for this buffer.- Specified by:
setReadOffset
in interfaceProtonBuffer
- Parameters:
value
- The offset into the buffer where the read offset should be positioned.- Returns:
- this buffer for use in chaining.
-
advanceReadOffset
Description copied from interface:ProtonBuffer
Adjusts the currentProtonBuffer.getReadOffset()
of this buffer by the specifiedlength
.- Specified by:
advanceReadOffset
in interfaceProtonBuffer
- Parameters:
length
- the number of bytes to advance the read offset by.- Returns:
- this ProtonBuffer for chaining.
-
setWriteOffset
Description copied from interface:ProtonBuffer
Sets the write offset for this buffer.- Specified by:
setWriteOffset
in interfaceProtonBuffer
- Parameters:
value
- The offset into the buffer where the write offset should be positioned.- Returns:
- this buffer for use in chaining.
-
advanceWriteOffset
Description copied from interface:ProtonBuffer
Adjusts the currentProtonBuffer.getWriteOffset()
of this buffer by the specifiedlength
.- Specified by:
advanceWriteOffset
in interfaceProtonBuffer
- Parameters:
length
- the number of bytes to advance the write offset by.- Returns:
- this ProtonBuffer for chaining.
-
implicitGrowthLimit
Description copied from interface:ProtonBuffer
Configures the limit assigned to this buffer if one was set which controls how large the capacity of the buffer can grow implicitly via write calls. Once the limit is hit any write call that requires more capacity than is currently available will throw an exception instead of allocating more space.When a capacity limit is hit the buffer can still be enlarged but must be done explicitly via the ensure writable APIs.
The growth limit set applies only to this buffer instance and is not carried over to a copied buffer of the split buffer created from any of the buffer split calls.
- Specified by:
implicitGrowthLimit
in interfaceProtonBuffer
- Parameters:
limit
- The limit to assign as the maximum capacity this buffer can grow- Returns:
- this buffer for using in call chaining.
-
ensureWritable
default ProtonCompositeBuffer ensureWritable(int amount) throws IndexOutOfBoundsException, IllegalArgumentException Description copied from interface:ProtonBuffer
Ensures that the requested number of bytes is available for write operations in the current buffer, growing the buffer if needed to meet the requested writable capacity. This method will not alter the write offset but may change the value returned from the capacity method if new buffer space is allocated.This method allows buffer compaction as a strategy to reclaim already read space to make room for additional writes. This implies that a composite buffer can reuse already read buffers to extend the buffer's writable space by moving them to the end of the set of composite buffers and reseting their index values to make them fully writable.
- Specified by:
ensureWritable
in interfaceProtonBuffer
- Parameters:
amount
- The number of bytes beyond the current write index needed.- Returns:
- this buffer for using in call chaining.
- Throws:
IndexOutOfBoundsException
- if the amount given would result in the buffer exceeding the maximum capacity for this buffer.IllegalArgumentException
- if the amount given is less than zero.
-
ensureWritable
ProtonCompositeBuffer ensureWritable(int size, int minimumGrowth, boolean allowCompaction) throws IndexOutOfBoundsException, IllegalArgumentException Description copied from interface:ProtonBuffer
Ensures that the requested number of bytes is available for write operations in the current buffer, growing the buffer if needed to meet the requested writable capacity. This method will not alter the write offset but may change the value returned from the capacity method if new buffer space is allocated. If the buffer cannot create the required number of byte via compaction then the buffer will be grown by either the requested number of bytes or by the minimum allowed value specified.This method allows buffer compaction as a strategy to reclaim already read space to make room for additional writes. This implies that a composite buffer can reuse already read buffers to extend the buffer's writable space by moving them to the end of the set of composite buffers and reseting their index values to make them fully writable.
- Specified by:
ensureWritable
in interfaceProtonBuffer
- Parameters:
size
- The number of bytes beyond the current write index needed.minimumGrowth
- The minimum number of byte that the buffer can grow byallowCompaction
- Can the buffer use compaction as a strategy to create more writable space.- Returns:
- this buffer for using in call chaining.
- Throws:
IndexOutOfBoundsException
- if the amount given would result in the buffer exceeding the maximum capacity for this buffer.IllegalArgumentException
- if the amount given is less than zero.
-
convertToReadOnly
ProtonCompositeBuffer convertToReadOnly()Description copied from interface:ProtonBuffer
Converts this buffer instance to a read-only buffer, any write operation that is performed on this buffer following this call will fail. A buffer cannot be made writable after this call.- Specified by:
convertToReadOnly
in interfaceProtonBuffer
- Returns:
- this buffer for use in chaining.
-
copy
Description copied from interface:ProtonBuffer
Create a deep copy of the readable bytes of this ProtonBuffer, the returned buffer can be modified without affecting the contents or position markers of this instance. The returned copy will not be read-only regardless of the read-only state of this buffer instance at the time of copy.- Specified by:
copy
in interfaceProtonBuffer
- Returns:
- a deep copy of this ProtonBuffer instance.
-
copy
Description copied from interface:ProtonBuffer
Returns a copy of this buffer's sub-region. Modifying the content of the returned buffer or this buffer does not affect each other at all. This method does not modify the value returned fromProtonBuffer.getReadOffset()
orProtonBuffer.getWriteOffset()
of this buffer.The returned buffer will not be read-only even if this buffer is and as such the contents will be a deep copy regardless of this buffer's read-only state.
- Specified by:
copy
in interfaceProtonBuffer
- Parameters:
index
- The index in this buffer where the copy should beginlength
- The number of bytes to copy to the new buffer from this one.- Returns:
- a new ProtonBuffer instance containing the copied bytes.
-
copy
Description copied from interface:ProtonBuffer
Returns a copy of this buffer's readable bytes and sets the read-only state of the returned buffer based on the value of the read-only flag. If this buffer is read-only and the flag indicates a read-only copy then the copy may be a shallow copy that references the readable bytes of the source buffer.- Specified by:
copy
in interfaceProtonBuffer
- Parameters:
readOnly
- Should the returned buffer be read-only or not.- Returns:
- a new ProtonBuffer instance containing the copied bytes.
-
copy
Description copied from interface:ProtonBuffer
Returns a copy of this buffer's sub-region. Modifying the content of the returned buffer or this buffer does not affect each other at all. This method does not modify the value returned fromProtonBuffer.getReadOffset()
orProtonBuffer.getWriteOffset()
of this buffer.If this buffer is read-only and the requested copy is also read-only the copy may be shallow and allow each buffer to share the same memory.
- Specified by:
copy
in interfaceProtonBuffer
- Parameters:
index
- The index in this buffer where the copy should beginlength
- The number of bytes to copy to the new buffer from this one.readOnly
- Should the returned buffer be read-only or not.- Returns:
- a new ProtonBuffer instance containing the copied bytes.
- Throws:
IllegalArgumentException
- if the offset or length given are out of bounds.
-
compact
ProtonCompositeBuffer compact()Description copied from interface:ProtonBuffer
Moves the readable portion of the buffer to the beginning of the underlying buffer storage and possibly makes additional bytes available for writes before a buffer expansion would occur via anProtonBuffer.ensureWritable(int)
call.- Specified by:
compact
in interfaceProtonBuffer
- Returns:
- this buffer for using in call chaining.
-
readSplit
Description copied from interface:ProtonBuffer
Splits this buffer at the read offset + the length given.- Specified by:
readSplit
in interfaceProtonBuffer
- Parameters:
length
- The number of bytes beyond the read offset where the split should occur- Returns:
- A new buffer that owns the memory spanning the range given.
-
writeSplit
Description copied from interface:ProtonBuffer
Splits this buffer at the write offset + the length given.- Specified by:
writeSplit
in interfaceProtonBuffer
- Parameters:
length
- The number of bytes beyond the write offset where the split should occur- Returns:
- A new buffer that owns the memory spanning the range given.
-
split
Description copied from interface:ProtonBuffer
Splits this buffer at the write offset.This creates two independent buffers that can manage differing views of the same memory region or in the case of a composite buffer two buffers that take ownership of differing sections of the composite buffer range. For a composite buffer a single buffer might be split if the offset lays within its bounds but all others buffers are divided amongst the two split buffers.
If this buffer is a read-only buffer then the resulting split buffer will also be read-only.
- Specified by:
split
in interfaceProtonBuffer
- Returns:
- A new buffer that owns the memory spanning the range given.
-
split
Description copied from interface:ProtonBuffer
Splits this buffer at the given offset.This creates two independent buffers that can manage differing views of the same memory region or in the case of a composite buffer two buffers that take ownership of differing sections of the composite buffer range. For a composite buffer a single buffer might be split if the offset lays within its bounds but all others buffers are divided amongst the two split buffers.
If this buffer is a read-only buffer then the resulting split buffer will also be read-only.
- Specified by:
split
in interfaceProtonBuffer
- Parameters:
splitOffset
- The offset in this buffer where the split should occur.- Returns:
- A new buffer that owns the memory spanning the range given.
-
writeBytes
Description copied from interface:ProtonBuffer
Writes into this buffer, all the readable bytes from the given buffer. This updates theProtonBuffer.getWriteOffset()
of this buffer, and theProtonBuffer.getReadOffset()
of the given buffer.- Specified by:
writeBytes
in interfaceProtonBuffer
- Parameters:
source
- The buffer to read from.- Returns:
- This buffer.
-
writeBytes
Description copied from interface:ProtonBuffer
Writes into this buffer, all the bytes from the given byte array. This updates the ProtonBuffer.getWriteOffset() of this buffer by the length of the array.- Specified by:
writeBytes
in interfaceProtonBuffer
- Parameters:
source
- The byte array to read from.- Returns:
- this buffer for using in call chaining.
-
writeBytes
Description copied from interface:ProtonBuffer
Writes into this buffer, the given number of bytes from the byte array. This updates the ProtonBuffer.getWriteOffset() of this buffer by the length argument. Implementations are recommended to specialize this method and provide a more efficient version.- Specified by:
writeBytes
in interfaceProtonBuffer
- Parameters:
source
- The byte array to read from.offset
- The position in thesource
from where bytes should be written to this buffer.length
- The number of bytes to copy.- Returns:
- this buffer for using in call chaining.
-
writeBytes
Description copied from interface:ProtonBuffer
Writes into this buffer from the sourceByteBuffer
. This updates theProtonBuffer.getWriteOffset()
of this buffer and also the position of the sourceByteBuffer
. Implementations are recommended to specialize this method and provide a more efficient version.Note: the behavior is undefined if the given
ByteBuffer
is an alias for the memory in this buffer.- Specified by:
writeBytes
in interfaceProtonBuffer
- Parameters:
source
- TheByteBuffer
to read from.- Returns:
- this buffer for using in call chaining.
-
readBytes
Description copied from interface:ProtonBuffer
Read from this buffer, into the destinationByteBuffer
This updates the read offset of this buffer and also the position of the destinationByteBuffer
.Note: the behavior is undefined if the given
ByteBuffer
is an alias for the memory in this buffer.- Specified by:
readBytes
in interfaceProtonBuffer
- Parameters:
destination
- TheByteBuffer
to write into.- Returns:
- this buffer for using in call chaining.
-
readBytes
Description copied from interface:ProtonBuffer
Read from this buffer, into the destination array, the given number of bytes. This updates the read offset of this buffer by the length argument.- Specified by:
readBytes
in interfaceProtonBuffer
- Parameters:
destination
- The byte array to write into.offset
- Position in thedestination
to where bytes should be written from this buffer.length
- The number of bytes to copy.- Returns:
- This buffer.
-