Class ByteArrayPool


  • public class ByteArrayPool
    extends java.lang.Object
    A pool of byte[]. When allocationThresholdEnabled==true, arrays with length <= allocationThreshold will be directly allocated and returning them will have no effect.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void returnArray​(byte[] array)
      Return a taken byte[] to the pool.
      byte[] takeArray​(int length)
      Take a byte[] with the specified length from the pool, or returns a directly allocated one if length <= allocationThreshold and allocationThresholdEnabled==true.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ByteArrayPool

        public ByteArrayPool()
      • ByteArrayPool

        public ByteArrayPool​(boolean allocationThresholdEnabled)
      • ByteArrayPool

        public ByteArrayPool​(int allocationThreshold)
    • Method Detail

      • takeArray

        public byte[] takeArray​(int length)
        Take a byte[] with the specified length from the pool, or returns a directly allocated one if length <= allocationThreshold and allocationThresholdEnabled==true.
        Parameters:
        length - Desired length.
        Returns:
        byte[] of requested length.
      • returnArray

        public void returnArray​(byte[] array)
        Return a taken byte[] to the pool.
        Parameters:
        array - byte[] to return.