private void expandCapacity(final int capacity) { final ByteBuffer oldbuffer = this.buffer; this.buffer = allocator.allocate(capacity); oldbuffer.flip(); this.buffer.put(oldbuffer); }
private void expandCapacity(final int capacity) { final ByteBuffer oldbuffer = this.buffer; this.buffer = allocator.allocate(capacity); oldbuffer.flip(); this.buffer.put(oldbuffer); }
/** * Allocates buffer of the given size using the given allocator. * * @param buffersize the buffer size. * @param allocator allocator to be used to allocate {@link ByteBuffer}s. */ public ExpandableBuffer(final int buffersize, final ByteBufferAllocator allocator) { super(); Args.notNull(allocator, "ByteBuffer allocator"); this.allocator = allocator; this.buffer = allocator.allocate(buffersize); this.mode = INPUT_MODE; }
/** * Allocates buffer of the given size using the given allocator. * * @param buffersize the buffer size. * @param allocator allocator to be used to allocate {@link ByteBuffer}s. */ public ExpandableBuffer(final int buffersize, final ByteBufferAllocator allocator) { super(); Args.notNull(allocator, "ByteBuffer allocator"); this.allocator = allocator; this.buffer = allocator.allocate(buffersize); this.mode = INPUT_MODE; }
public ControlledByteBuffer getBuffer() { if (marker == -1) { // System.out.println("allocating marker -1"); return new ControlledByteBuffer(allocator.allocate(bufferSize)); } else { try { lock.lock(); if (marker >= 0) { // System.out.println("Returning buffer"); ControlledByteBuffer controlledByteBuffer = buffers[marker]; controlledByteBuffer.clear(); controlledByteBuffer.forceSetInputMode(); buffers[marker] = null; marker--; return controlledByteBuffer; } } finally { lock.unlock(); } } return new ControlledByteBuffer(allocator.allocate(bufferSize)); }