public final class CachingBufferPool extends java.lang.Object implements BufferPool
BufferPool implementation which caches values at fixed sizes.
Pooled instances are held as SoftReference to allow GC if necessary.
The current fixed sizes are calculated as follows:
Integer.MAX_VALUE| Modifier and Type | Method and Description |
|---|---|
byte[] |
allocateArray(int size)
Returns a
byte[] of size or greater length. |
java.nio.ByteBuffer |
allocateDirect(int size)
Returns a
direct ByteBuffer of size or
greater capacity. |
static BufferPool |
getInstance()
Returns instance of
CachingBufferPool for using cached buffers. |
void |
releaseArray(byte[] buffer)
Returns instance to pool for potential future reuse.
|
void |
releaseDirect(java.nio.ByteBuffer buffer)
Returns instance to pool for potential future reuse.
|
java.lang.String |
toString() |
public static BufferPool getInstance()
CachingBufferPool for using cached buffers.CachingBufferPool for using cached buffers.public byte[] allocateArray(int size)
byte[] of size or greater length.allocateArray in interface BufferPoolsize - The minimum size array required. Must be >= 0.byte[] with length of at least size.BufferPool.releaseArray(byte[])public void releaseArray(byte[] buffer)
Must not be returned more than 1 time. Must not be used by caller after return.
releaseArray in interface BufferPoolbuffer - Instance to return to pool. Must not be null.
Must not be returned more than 1 time. Must not be used by caller after return.public java.nio.ByteBuffer allocateDirect(int size)
direct ByteBuffer of size or
greater capacity.allocateDirect in interface BufferPoolsize - The minimum size buffer required. Must be >= 0.ByteBuffer of size or greater capacity.BufferPool.releaseDirect(ByteBuffer),
ByteBuffer.allocateDirect(int)public void releaseDirect(java.nio.ByteBuffer buffer)
Must not be returned more than 1 time. Must not be used by caller after return.
releaseDirect in interface BufferPoolbuffer - Instance to return to pool. Must not be null.
Must not be returned more than 1 time. Must not be used by caller after return.public java.lang.String toString()
toString in class java.lang.Object