org.apache.hc.core5.http.impl.nio

## Class ExpandableBuffer

- java.lang.Object
- - org.apache.hc.core5.http.impl.nio.ExpandableBuffer

- Direct Known Subclasses:
    BufferedData, SharedInputBuffer, SharedOutputBuffer

      @Internal
      public class ExpandableBuffer
      extends Object

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

  This class is not thread safe.

  Since:
    4.0

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static class` | `ExpandableBuffer.Mode`

  - ### Constructor Summary

    Constructors
    Modifier | Constructor and Description
    --- | ---
    `protected` | `ExpandableBuffer(int bufferSize)` Allocates buffer of the given size using the given allocator.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected ByteBuffer` | `buffer()`
    `protected int` | `capacity()` Returns available capacity of this buffer.
    `protected void` | `clear()` Clears buffer.
    `protected void` | `ensureAdjustedCapacity(int requiredCapacity)` Ensures the buffer can accommodate at least the required capacity adjusted to multiples of 1024.
    `protected void` | `ensureCapacity(int requiredCapacity)` Ensures the buffer can accommodate the exact required capacity.
    `protected void` | `expand()` Expands buffer's capacity.
    `protected boolean` | `hasData()` Determines if the buffer contains data.
    `protected int` | `length()` Returns the length of this buffer.
    `protected ExpandableBuffer.Mode` | `mode()` Returns the current mode:
    `protected void` | `setInputMode()` Sets the mode to input.
    `protected void` | `setOutputMode()` Sets the mode to output.
    `String` | `toString()`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Constructor Detail

    - #### ExpandableBuffer

          protected ExpandableBuffer(int bufferSize)

      Allocates buffer of the given size using the given allocator.

      Sets the mode to input.

      Parameters:
        `bufferSize` - the buffer size.

  - ### Method Detail

    - #### mode

          protected ExpandableBuffer.Mode mode()

      Returns the current mode:

      `ExpandableBuffer.Mode.INPUT`: the buffer is in the input mode.

      `ExpandableBuffer.Mode.OUTPUT`: the buffer is in the output mode.

      Returns:
        current input/output mode.

    - #### buffer

          protected ByteBuffer buffer()

    - #### setOutputMode

          protected void setOutputMode()

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

    - #### setInputMode

          protected void setInputMode()

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

    - #### expand

          protected void expand()
                         throws BufferOverflowException

      Expands buffer's capacity.
      Throws:
        `BufferOverflowException` - in case we get over the maximum allowed value

    - #### ensureCapacity

          protected void ensureCapacity(int requiredCapacity)

      Ensures the buffer can accommodate the exact required capacity.
      Parameters:
        `requiredCapacity` - the required capacity.

    - #### ensureAdjustedCapacity

          protected void ensureAdjustedCapacity(int requiredCapacity)

      Ensures the buffer can accommodate at least the required capacity adjusted to multiples of 1024.
      Parameters:
        `requiredCapacity` - the required capacity.

    - #### hasData

          protected boolean hasData()

      Determines if the buffer contains data.

      Sets the mode to output.

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

    - #### length

          protected int length()

      Returns the length of this buffer.

      Sets the mode to output.

      Returns:
        buffer length.

    - #### capacity

          protected int capacity()

      Returns available capacity of this buffer.
      Returns:
        buffer length.

    - #### clear

          protected void clear()

      Clears buffer.

      Sets the mode to input.

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`

Copyright © 2005–2021 The Apache Software Foundation. All rights reserved.