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