com.hazelcast.client.impl.protocol.util
Class BufferBuilder

java.lang.Object
  extended by com.hazelcast.client.impl.protocol.util.BufferBuilder

public class BufferBuilder
extends Object

Builder for appending buffers that grows capacity as necessary.


Field Summary
static int INITIAL_CAPACITY
           
 
Constructor Summary
BufferBuilder()
          Construct a buffer builder with a default growth increment of INITIAL_CAPACITY
BufferBuilder(int initialCapacity)
          Construct a buffer builder with an initial capacity that will be rounded up to the nearest power of 2.
 
Method Summary
 BufferBuilder append(DirectBuffer srcBuffer, int srcOffset, int length)
          Append a source buffer to the end of the internal buffer, resizing the internal buffer as required.
 MutableDirectBuffer buffer()
          The MutableDirectBuffer that encapsulates the internal buffer.
 int capacity()
          The current capacity of the buffer.
 BufferBuilder compact()
          Compact the buffer to reclaim unused space above the limit.
 int limit()
          The current limit of the buffer that has been used by accumulate operations.
 BufferBuilder reset()
          Reset the builder to restart accumulate operations.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

INITIAL_CAPACITY

public static final int INITIAL_CAPACITY
See Also:
Constant Field Values
Constructor Detail

BufferBuilder

public BufferBuilder()
Construct a buffer builder with a default growth increment of INITIAL_CAPACITY


BufferBuilder

public BufferBuilder(int initialCapacity)
Construct a buffer builder with an initial capacity that will be rounded up to the nearest power of 2.

Parameters:
initialCapacity - at which the capacity will start.
Method Detail

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 accumulate operations.

Returns:
the current limit of the buffer that has been used by accumulate operations.

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 accumulate 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 as 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.


Copyright © 2015 Hazelcast, Inc.. All Rights Reserved.