/** * Creates a new instance of a {@link ByteArray} * * @param size * The size of the array to build */ public ByteArray create(int size) { if (size < 1) { throw new IllegalArgumentException("Buffer size must be at least 1: " + size); } int bits = bits(size); synchronized (this) { if (!freeBuffers.get(bits).isEmpty()) { DirectBufferByteArray ba = freeBuffers.get(bits).pop(); ba.setFreed(false); ba.getSingleIoBuffer().limit(size); return ba; } } IoBuffer bb; int bbSize = 1 << bits; bb = IoBuffer.allocate(bbSize, direct); bb.limit(size); DirectBufferByteArray ba = new DirectBufferByteArray(bb); ba.setFreed(false); return ba; }
/** * Creates a new instance of a {@link ByteArray} * * @param size * The size of the array to build */ public ByteArray create(int size) { if (size < 1) { throw new IllegalArgumentException("Buffer size must be at least 1: " + size); } int bits = bits(size); synchronized (this) { if (!freeBuffers.get(bits).isEmpty()) { DirectBufferByteArray ba = freeBuffers.get(bits).pop(); ba.setFreed(false); ba.getSingleIoBuffer().limit(size); return ba; } } IoBuffer bb; int bbSize = 1 << bits; bb = IoBuffer.allocate(bbSize, direct); bb.limit(size); DirectBufferByteArray ba = new DirectBufferByteArray(bb); ba.setFreed(false); return ba; }