Class BufferRecycler

java.lang.Object
org.apache.james.mime4j.util.BufferRecycler

public class BufferRecycler extends Object
This is a small utility class, whose main functionality is to allow simple reuse of raw byte/char buffers. It is usually used through ThreadLocal member of the owning class pointing to instance of this class through a SoftReference. The end result is a low-overhead GC-cleanable recycling: hopefully ideal for use by stream readers.

Rewritten in 2.10 to be thread-safe (see [jackson-core#479] for details), to not rely on ThreadLocal access.

  • Field Details

    • ENABLED

      static final boolean ENABLED
    • _byteBuffers

      protected final ArrayList<byte[]>[] _byteBuffers
    • _charBuffers

      protected final ArrayList<char[]>[] _charBuffers
    • _intBuffers

      protected final ArrayList<int[]> _intBuffers
  • Constructor Details

    • BufferRecycler

      public BufferRecycler()
      Default constructor used for creating instances of this default implementation.
    • BufferRecycler

      protected BufferRecycler(int bbCount, int cbCount)
      Alternate constructor to be used by sub-classes, to allow customization of number of low-level buffers in use.
      Parameters:
      bbCount - Number of byte[] buffers to allocate
      cbCount - Number of char[] buffers to allocate
      Since:
      2.4
  • Method Details

    • allocByteBuffer

      public final byte[] allocByteBuffer(int ix)
      Parameters:
      ix - One of READ_IO_BUFFER constants.
      Returns:
      Buffer allocated (possibly recycled)
    • allocintBuffer

      public final int[] allocintBuffer(int minSize)
    • allocByteBuffer

      public byte[] allocByteBuffer(int ix, int minSize)
    • releaseByteBuffer

      public void releaseByteBuffer(int ix, byte[] buffer)
    • releaseIntBuffer

      public void releaseIntBuffer(int[] buffer)
    • allocCharBuffer

      public final char[] allocCharBuffer(int ix)
    • allocCharBuffer

      public char[] allocCharBuffer(int ix, int minSize)
    • releaseCharBuffer

      public void releaseCharBuffer(int ix, char[] buffer)
    • balloc

      protected byte[] balloc(int size)
    • calloc

      protected char[] calloc(int size)