## org.apache.http.nio.util
Class ExpandableBuffer

    java.lang.Object
      org.apache.http.nio.util.ExpandableBuffer

All Implemented Interfaces:
  BufferInfo

Direct Known Subclasses:
  SessionInputBufferImpl, SessionOutputBufferImpl, SharedInputBuffer, SharedOutputBuffer, SimpleInputBuffer, SimpleOutputBuffer

    @NotThreadSafe
    public class ExpandableBuffer

extends Object
implements BufferInfo, BufferInfo

A buffer that expand its capacity on demand using `ByteBufferAllocator` interface. Internally, this class is backed by an instance of `ByteBuffer`.

This class is not thread safe.

Since:
  4.0

Field Summary
`protected ByteBuffer` `buffer`
`static int` `INPUT_MODE`
`static int` `OUTPUT_MODE`

Constructor Summary
`ExpandableBuffer(int buffersize, ByteBufferAllocator allocator)` Allocates buffer of the given size using the given allocator.

Method Summary
`int` `available()` Returns available capacity of this buffer.
`int` `capacity()` Returns the total capacity of this buffer.
`protected void` `clear()` Clears buffer.
`protected void` `ensureCapacity(int requiredCapacity)` Ensures the buffer can accommodate the required capacity.
`protected void` `expand()` Expands buffer's capacity.
`protected int` `getMode()` Returns the current mode:
`boolean` `hasData()` Determines if the buffer contains data.
`int` `length()` Returns the length of this buffer.
`protected void` `setInputMode()` Sets input mode.
`protected void` `setOutputMode()` Sets output mode.
`String` `toString()`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

Field Detail

### INPUT_MODE

    public static final int INPUT_MODE

See Also:
  Constant Field Values

### OUTPUT_MODE

    public static final int OUTPUT_MODE

See Also:
  Constant Field Values

### buffer

    protected ByteBuffer buffer

Constructor Detail

### ExpandableBuffer

    public ExpandableBuffer(int buffersize,
                            ByteBufferAllocator allocator)

  Allocates buffer of the given size using the given allocator.

  Parameters:
    `buffersize` - the buffer size.
    `allocator` - allocator to be used to allocate `ByteBuffer`s.

Method Detail

### getMode

    protected int getMode()

  Returns the current mode:

  `INPUT_MODE`: the buffer is in the input mode.

  `OUTPUT_MODE`: the buffer is in the output mode.

  Returns:
    current input/output mode.

### setOutputMode

    protected void setOutputMode()

  Sets output mode. The buffer can now be read from.

### setInputMode

    protected void setInputMode()

  Sets input mode. The buffer can now be written into.

### expand

    protected void expand()

  Expands buffer's capacity.

### ensureCapacity

    protected void ensureCapacity(int requiredCapacity)

  Ensures the buffer can accommodate the required capacity.

  Parameters:
    `requiredCapacity` -

### capacity

    public int capacity()

  Returns the total capacity of this buffer.

  Specified by:
    `capacity` in interface `BufferInfo`
  Returns:
    total capacity.

### hasData

    public boolean hasData()

  Determines if the buffer contains data.

  Returns:
    `true` if there is data in the buffer, `false` otherwise.

### length

    public int length()

  Returns the length of this buffer.

  Specified by:
    `length` in interface `BufferInfo`
  Returns:
    buffer length.

### available

    public int available()

  Returns available capacity of this buffer.

  Specified by:
    `available` in interface `BufferInfo`
  Returns:
    buffer length.

### clear

    protected void clear()

  Clears buffer.

### toString

    public String toString()

  Overrides:
    `toString` in class `Object`

Copyright © 2005-2013 The Apache Software Foundation. All Rights Reserved.