/** * Tests <code>BufferPool</code> with <code>ByteBuffer</code> buffers. * * <p>This method invokes {@link #testBuffer(com.mucommander.commons.io.BufferPool.BufferFactory)} with a * {@link BufferPool.ByteBufferFactory} instance.</p> */ @Test public void testByteBuffer() { testBuffer(new BufferPool.ByteBufferFactory()); }
/** * Returns a ByteBuffer of the specified capacity. This method first checks if a ByteBuffer instance of the * specified capacity exists in the pool. If one is found, it is removed from the pool and returned. If not, * a new instance is created and returned. * * <p>This method won't return the same buffer instance until it has been released with * {@link #releaseByteBuffer(ByteBuffer)}.</p> * * <p>This method is a shorthand for {@link #getBuffer(com.mucommander.commons.io.BufferPool.BufferFactory,int)} called * with a {@link com.mucommander.commons.io.BufferPool.ByteBufferFactory} instance.</p>. * @param capacity capacity of the ByteBuffer * @return a ByteBuffer with the specified capacity */ public static synchronized ByteBuffer getByteBuffer(int capacity) { return (ByteBuffer)getBuffer(new ByteBufferFactory(), capacity); }
/** * Makes the given buffer available for further calls to {@link #getByteBuffer(int)} with the same buffer capacity. * Returns <code>true</code> if the buffer was added to the pool, <code>false</code> if the buffer was already in * the pool. * * <p>After calling this method, the given buffer instance <b>must not be used</b>, otherwise it could get * corrupted if other threads were using it.</p> * * @param buffer the buffer instance to make available for further use * @return <code>true</code> if the buffer was added to the pool, <code>false</code> if the buffer was already in the pool * @throws IllegalArgumentException if specified buffer is null */ public static synchronized boolean releaseByteBuffer(ByteBuffer buffer) { return releaseBuffer(buffer, new ByteBufferFactory()); }