Class BufferRecycler
java.lang.Object
org.apache.james.mime4j.util.BufferRecycler
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 Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionDefault constructor used for creating instances of this default implementation.protectedBufferRecycler(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
Modifier and TypeMethodDescriptionfinal byte[]allocByteBuffer(int ix) byte[]allocByteBuffer(int ix, int minSize) final char[]allocCharBuffer(int ix) char[]allocCharBuffer(int ix, int minSize) final int[]allocintBuffer(int minSize) protected byte[]balloc(int size) protected char[]calloc(int size) voidreleaseByteBuffer(int ix, byte[] buffer) voidreleaseCharBuffer(int ix, char[] buffer) voidreleaseIntBuffer(int[] buffer)
-
Field Details
-
ENABLED
static final boolean ENABLED -
_byteBuffers
-
_charBuffers
-
_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 ofbyte[]buffers to allocatecbCount- Number ofchar[]buffers to allocate- Since:
- 2.4
-
-
Method Details
-
allocByteBuffer
public final byte[] allocByteBuffer(int ix) - Parameters:
ix- One ofREAD_IO_BUFFERconstants.- 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)
-