Package io.aeron
Class BufferBuilder
java.lang.Object
io.aeron.BufferBuilder
Reusable Builder for appending a sequence of buffer fragments which grows internal capacity as needed.
The underlying buffer can be byte[] backed or a direct ByteBuffer if the isDirect param to the constructor
is true.
Similar in concept to StringBuilder.
-
Constructor Summary
ConstructorsConstructorDescriptionConstruct a buffer builder with an initial capacity of zero and isDirect false.BufferBuilder(int initialCapacity) Construct a buffer builder with an initial capacity and isDirect false.BufferBuilder(int initialCapacity, boolean isDirect) Construct a buffer builder with an initial capacity. -
Method Summary
Modifier and TypeMethodDescriptionappend(DirectBuffer srcBuffer, int srcOffset, int length) Append a source buffer to the end of the internal buffer, resizing the internal buffer when required.buffer()TheMutableDirectBufferthat encapsulates the internal buffer.intcapacity()The current capacity of the buffer.captureHeader(Header header) Capture information available in the header of the very first frame.compact()Compact the buffer to reclaim unused space above the limit.completeHeader(Header header) Use the information from the header of the last frame to create a header for the assembled message, i.e.intlimit()The current limit of the buffer that has been used by append operations.voidlimit(int limit) Set this limit for this buffer as the position at which the next append operation will occur.intGet the value which the next term offset for a fragment to be assembled should begin at.voidnextTermOffset(int offset) Set the value which the next term offset for a fragment to be assembled should begin at.reset()Reset the builder to restart append operations.
-
Constructor Details
-
BufferBuilder
public BufferBuilder()Construct a buffer builder with an initial capacity of zero and isDirect false. -
BufferBuilder
public BufferBuilder(int initialCapacity) Construct a buffer builder with an initial capacity and isDirect false.- Parameters:
initialCapacity- at which the capacity will start.
-
BufferBuilder
public BufferBuilder(int initialCapacity, boolean isDirect) Construct a buffer builder with an initial capacity.- Parameters:
initialCapacity- at which the capacity will start.isDirect- is the underlying buffer to be a directByteBuffer
-
-
Method Details
-
capacity
public int capacity()The current capacity of the buffer.- Returns:
- the current capacity of the buffer.
-
limit
public int limit()The current limit of the buffer that has been used by append operations.- Returns:
- the current limit of the buffer that has been used by append operations.
-
limit
public void limit(int limit) Set this limit for this buffer as the position at which the next append operation will occur.- Parameters:
limit- to be the new value.
-
nextTermOffset
public int nextTermOffset()Get the value which the next term offset for a fragment to be assembled should begin at.- Returns:
- the value which the next term offset for a fragment to be assembled should begin at.
-
nextTermOffset
public void nextTermOffset(int offset) Set the value which the next term offset for a fragment to be assembled should begin at.- Parameters:
offset- which the next term offset for a fragment to be assembled should begin at.
-
buffer
TheMutableDirectBufferthat encapsulates the internal buffer.- Returns:
- the
MutableDirectBufferthat encapsulates the internal buffer.
-
reset
Reset the builder to restart append operations. The internal buffer does not shrink.- Returns:
- the builder for fluent API usage.
-
compact
Compact the buffer to reclaim unused space above the limit.- Returns:
- the builder for fluent API usage.
-
append
Append a source buffer to the end of the internal buffer, resizing the internal buffer when required.- Parameters:
srcBuffer- from which to copy.srcOffset- in the source buffer from which to copy.length- in bytes to copy from the source buffer.- Returns:
- the builder for fluent API usage.
-
captureHeader
Capture information available in the header of the very first frame.- Parameters:
header- of the first frame.- Returns:
- the builder for fluent API usage.
-
completeHeader
Use the information from the header of the last frame to create a header for the assembled message, i.e. fixups the flags and the frame length.- Parameters:
header- of the last frame.- Returns:
- complete message header.
-