/** * Tests <code>BufferPool</code> with byte array (<code>byte[]</code>) buffers. * * <p>This method invokes {@link #testBuffer(com.mucommander.commons.io.BufferPool.BufferFactory)} with a * {@link BufferPool.ByteArrayFactory} instance.</p> */ @Test public void testByteArrayBuffer() { testBuffer(new BufferPool.ByteArrayFactory()); }
/** * Returns a byte array of the specified length. This method first checks if a byte array of the specified length * 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 #releaseByteArray(byte[])}.</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.ByteArrayFactory} instance.</p>. * * @param length length of the byte array * @return a byte array of the specified size */ public static synchronized byte[] getByteArray(int length) { return (byte[])getBuffer(new ByteArrayFactory(), length); }
/** * Makes the given buffer available for further calls to {@link #getByteArray(int)} with the same buffer length. * 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 releaseByteArray(byte buffer[]) { return releaseBuffer(buffer, new ByteArrayFactory()); }