Package org.apache.james.mime4j.util
Class BufferRecycler
- java.lang.Object
-
- org.apache.james.mime4j.util.BufferRecycler
-
public class BufferRecycler extends java.lang.Object
This is a small utility class, whose main functionality is to allow simple reuse of raw byte/char buffers. It is usually used throughThreadLocal
member of the owning class pointing to instance of this class through aSoftReference
. 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 Summary
Fields Modifier and Type Field Description protected java.util.ArrayList<byte[]>[]
_byteBuffers
protected java.util.ArrayList<char[]>[]
_charBuffers
protected java.util.ArrayList<int[]>
_intBuffers
(package private) static boolean
ENABLED
-
Constructor Summary
Constructors Modifier Constructor Description BufferRecycler()
Default constructor used for creating instances of this default implementation.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.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description byte[]
allocByteBuffer(int ix)
byte[]
allocByteBuffer(int ix, int minSize)
char[]
allocCharBuffer(int ix)
char[]
allocCharBuffer(int ix, int minSize)
int[]
allocintBuffer(int minSize)
protected byte[]
balloc(int size)
protected char[]
calloc(int size)
void
releaseByteBuffer(int ix, byte[] buffer)
void
releaseCharBuffer(int ix, char[] buffer)
void
releaseIntBuffer(int[] buffer)
-
-
-
Constructor Detail
-
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 ofbyte[]
buffers to allocatecbCount
- Number ofchar[]
buffers to allocate- Since:
- 2.4
-
-
Method Detail
-
allocByteBuffer
public final byte[] allocByteBuffer(int ix)
- Parameters:
ix
- One ofREAD_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)
-
-