Package io.aeron

Class BufferBuilder

java.lang.Object
io.aeron.BufferBuilder

public final class BufferBuilder extends Object
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

    Constructors
    Constructor
    Description
    Construct 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 Type
    Method
    Description
    append(DirectBuffer srcBuffer, int srcOffset, int length)
    Append a source buffer to the end of the internal buffer, resizing the internal buffer when required.
    The MutableDirectBuffer that encapsulates the internal buffer.
    int
    The current capacity of the buffer.
    Capture information available in the header of the very first frame.
    Compact the buffer to reclaim unused space above the limit.
    Use the information from the header of the last frame to create a header for the assembled message, i.e.
    int
    The current limit of the buffer that has been used by append operations.
    void
    limit(int limit)
    Set this limit for this buffer as the position at which the next append operation will occur.
    int
    Get the value which the next term offset for a fragment to be assembled should begin at.
    void
    nextTermOffset(int offset)
    Set the value which the next term offset for a fragment to be assembled should begin at.
    Reset the builder to restart append operations.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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 direct ByteBuffer
  • 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

      public MutableDirectBuffer buffer()
      The MutableDirectBuffer that encapsulates the internal buffer.
      Returns:
      the MutableDirectBuffer that encapsulates the internal buffer.
    • reset

      public BufferBuilder reset()
      Reset the builder to restart append operations. The internal buffer does not shrink.
      Returns:
      the builder for fluent API usage.
    • compact

      public BufferBuilder compact()
      Compact the buffer to reclaim unused space above the limit.
      Returns:
      the builder for fluent API usage.
    • append

      public BufferBuilder append(DirectBuffer srcBuffer, int srcOffset, int length)
      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

      public BufferBuilder captureHeader(Header header)
      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

      public Header completeHeader(Header header)
      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.