Interface ProtonCompositeBuffer
- All Superinterfaces:
AutoCloseable,Comparable<ProtonBuffer>,ProtonBuffer,ProtonBufferAccessors,Resource<ProtonBuffer>
- All Known Implementing Classes:
ProtonCompositeBufferImpl
-
Method Summary
Modifier and TypeMethodDescriptiondefault ProtonCompositeBufferadvanceReadOffset(int length) Adjusts the currentProtonBuffer.getReadOffset()of this buffer by the specifiedlength.default ProtonCompositeBufferadvanceWriteOffset(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 ProtonCompositeBuffercopy()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 ProtonCompositeBuffercopy(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 ProtonCompositeBuffercopy(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 ProtonCompositeBuffercreate(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 ProtonCompositeBuffercreate(ProtonBufferAllocator allocator, ProtonBuffer buffer) Create an composite buffer with the given buffer instance as the initial buffer payload.static ProtonCompositeBuffercreate(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 ProtonCompositeBufferensureWritable(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 booleanisComposite(ProtonBuffer buffer) Checks if the given buffer is an composite buffer instance or not.default ProtonCompositeBufferreadBytes(byte[] destination, int offset, int length) Read from this buffer, into the destination array, the given number of bytes.default ProtonCompositeBufferreadBytes(ByteBuffer destination) Read from this buffer, into the destinationByteBufferThis updates the read offset of this buffer and also the position of the destinationByteBuffer.default ProtonCompositeBufferreadSplit(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 ProtonCompositeBuffersplit()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 ProtonCompositeBufferwriteBytes(byte[] source) Writes into this buffer, all the bytes from the given byte array.default ProtonCompositeBufferwriteBytes(byte[] source, int offset, int length) Writes into this buffer, the given number of bytes from the byte array.default ProtonCompositeBufferwriteBytes(ByteBuffer source) Writes into this buffer from the sourceByteBuffer.default ProtonCompositeBufferwriteBytes(ProtonBuffer source) Writes into this buffer, all the readable bytes from the given buffer.default ProtonCompositeBufferwriteSplit(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, writeCharSequenceMethods 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
ProtonCompositeBufferthat 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
ProtonCompositeBufferthat owns all buffers up to and including the buffer that holds given index.
-
fill
Description copied from interface:ProtonBufferAssigns the given value to every byte in the buffer without respect for the buffer read or write offsets.- Specified by:
fillin interfaceProtonBuffer- Parameters:
value- The byte value to assign each byte in this buffer.- Returns:
- this ProtonBuffer for chaining.
-
setReadOffset
Description copied from interface:ProtonBufferSets the read offset for this buffer.- Specified by:
setReadOffsetin 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:ProtonBufferAdjusts the currentProtonBuffer.getReadOffset()of this buffer by the specifiedlength.- Specified by:
advanceReadOffsetin interfaceProtonBuffer- Parameters:
length- the number of bytes to advance the read offset by.- Returns:
- this ProtonBuffer for chaining.
-
setWriteOffset
Description copied from interface:ProtonBufferSets the write offset for this buffer.- Specified by:
setWriteOffsetin 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:ProtonBufferAdjusts the currentProtonBuffer.getWriteOffset()of this buffer by the specifiedlength.- Specified by:
advanceWriteOffsetin interfaceProtonBuffer- Parameters:
length- the number of bytes to advance the write offset by.- Returns:
- this ProtonBuffer for chaining.
-
implicitGrowthLimit
Description copied from interface:ProtonBufferConfigures 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:
implicitGrowthLimitin 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:ProtonBufferEnsures 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:
ensureWritablein 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:ProtonBufferEnsures 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:
ensureWritablein 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:ProtonBufferConverts 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:
convertToReadOnlyin interfaceProtonBuffer- Returns:
- this buffer for use in chaining.
-
copy
Description copied from interface:ProtonBufferCreate 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:
copyin interfaceProtonBuffer- Returns:
- a deep copy of this ProtonBuffer instance.
-
copy
Description copied from interface:ProtonBufferReturns 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:
copyin 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:ProtonBufferReturns 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:
copyin 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:ProtonBufferReturns 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:
copyin 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:ProtonBufferMoves 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:
compactin interfaceProtonBuffer- Returns:
- this buffer for using in call chaining.
-
readSplit
Description copied from interface:ProtonBufferSplits this buffer at the read offset + the length given.- Specified by:
readSplitin 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:ProtonBufferSplits this buffer at the write offset + the length given.- Specified by:
writeSplitin 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:ProtonBufferSplits 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:
splitin interfaceProtonBuffer- Returns:
- A new buffer that owns the memory spanning the range given.
-
split
Description copied from interface:ProtonBufferSplits 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:
splitin 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:ProtonBufferWrites 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:
writeBytesin interfaceProtonBuffer- Parameters:
source- The buffer to read from.- Returns:
- This buffer.
-
writeBytes
Description copied from interface:ProtonBufferWrites 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:
writeBytesin interfaceProtonBuffer- Parameters:
source- The byte array to read from.- Returns:
- this buffer for using in call chaining.
-
writeBytes
Description copied from interface:ProtonBufferWrites 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:
writeBytesin interfaceProtonBuffer- Parameters:
source- The byte array to read from.offset- The position in thesourcefrom 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:ProtonBufferWrites 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
ByteBufferis an alias for the memory in this buffer.- Specified by:
writeBytesin interfaceProtonBuffer- Parameters:
source- TheByteBufferto read from.- Returns:
- this buffer for using in call chaining.
-
readBytes
Description copied from interface:ProtonBufferRead from this buffer, into the destinationByteBufferThis updates the read offset of this buffer and also the position of the destinationByteBuffer.Note: the behavior is undefined if the given
ByteBufferis an alias for the memory in this buffer.- Specified by:
readBytesin interfaceProtonBuffer- Parameters:
destination- TheByteBufferto write into.- Returns:
- this buffer for using in call chaining.
-
readBytes
Description copied from interface:ProtonBufferRead 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:
readBytesin interfaceProtonBuffer- Parameters:
destination- The byte array to write into.offset- Position in thedestinationto where bytes should be written from this buffer.length- The number of bytes to copy.- Returns:
- This buffer.
-