Class ByteBufferPool

java.lang.Object
com.sshtools.common.util.ByteBufferPool

public class ByteBufferPool extends Object
This class provides a pool for either direct or non direct ByteBuffers.
  • Constructor Details

    • ByteBufferPool

      public ByteBufferPool()
      Create a default pool of ByteBuffers with 4k capacity
    • ByteBufferPool

      public ByteBufferPool(int capacity, boolean direct)
      Create a pool of ByteBuffers.
      Parameters:
      capacity - int
      direct - boolean
  • Method Details

    • getCapacity

      public int getCapacity()
      Get the capacity of buffers in this pool.
      Returns:
      int
    • getAllocatedBuffers

      public int getAllocatedBuffers()
      Get the number of buffers currently allocated out.
      Returns:
      int
    • getFreeBuffers

      public int getFreeBuffers()
      Get the number of buffers that are ready to be allocated.
      Returns:
      int
    • getTotalMemoryInUse

      public long getTotalMemoryInUse()
      Calculate the total memory in use by this pool.
      Returns:
      long
    • getTotalMemoryAllocated

      public long getTotalMemoryAllocated()
      Calculate the total memory allocated by this pool.
      Returns:
      long
    • get

      public ByteBuffer get()
      Get a free buffer from the pool.
      Returns:
      ByteBuffer
    • add

      public void add(ByteBuffer buffer)
      Add a buffer back to the pool.
      Parameters:
      buffer - ByteBuffer