/** * Allocate buffer using set buffer type and buffer size. * * @return allocated ByteBuffer */ public ByteBuffer allocateBuffer() { return bufferType.allocate(bufferSize); }
/** * Allocate buffer using set buffer type and buffer size. * * @return allocated ByteBuffer */ public ByteBuffer allocateBuffer() { return bufferType.allocate(bufferSize); }
/** * Allocate buffer using set buffer type and buffer size. * * @return allocated ByteBuffer */ public ByteBuffer allocateBuffer() { return bufferType.allocate(bufferSize); }
/** * Allocate buffer using set buffer type and buffer size. * * @return allocated ByteBuffer */ public ByteBuffer allocateBuffer() { return bufferType.allocate(bufferSize); }
public ByteBuffer createBuffer(BufferType bufferType) { usedBuffers.incrementAndGet(); ByteBuffer buf = bufferPool.poll(); if (buf != null) { buf.clear(); return buf; } return bufferType.allocate(bufferSize); }
public ByteBuffer createBuffer(BufferType bufferType) { usedBuffers.incrementAndGet(); ByteBuffer buf = bufferPool.poll(); if (buf != null) { buf.clear(); return buf; } return bufferType.allocate(bufferSize); }
public ByteBuffer createBuffer(BufferType bufferType) { usedBuffers.incrementAndGet(); ByteBuffer buf = bufferPool.poll(); if (buf != null) { buf.clear(); return buf; } return bufferType.allocate(bufferSize); }
/** * Ensure {@code buf} is large enough for {@code outputLength}. If not, it is cleaned up and a new buffer is allocated; * else; buffer has it's position/limit set appropriately. * * @param buf buffer to test the size of; may be null, in which case, a new buffer is allocated. * @param outputLength the minimum target size of the buffer * @param allowBufferResize true if resizing (reallocating) the buffer is allowed * @param bufferType on- or off- heap byte buffer * @return {@code buf} if it was large enough, else a newly allocated buffer. */ public static ByteBuffer ensureCapacity(ByteBuffer buf, int outputLength, boolean allowBufferResize, BufferType bufferType) { if (0 > outputLength) throw new IllegalArgumentException("invalid size for output buffer: " + outputLength); if (buf == null || buf.capacity() < outputLength) { if (!allowBufferResize) throw new IllegalStateException(String.format("output buffer is not large enough for data: current capacity %d, required %d", buf.capacity(), outputLength)); FileUtils.clean(buf); buf = bufferType.allocate(outputLength); } else { buf.position(0).limit(outputLength); } return buf; }
/** * Ensure {@code buf} is large enough for {@code outputLength}. If not, it is cleaned up and a new buffer is allocated; * else; buffer has it's position/limit set appropriately. * * @param buf buffer to test the size of; may be null, in which case, a new buffer is allocated. * @param outputLength the minimum target size of the buffer * @param allowBufferResize true if resizing (reallocating) the buffer is allowed * @param bufferType on- or off- heap byte buffer * @return {@code buf} if it was large enough, else a newly allocated buffer. */ public static ByteBuffer ensureCapacity(ByteBuffer buf, int outputLength, boolean allowBufferResize, BufferType bufferType) { if (0 > outputLength) throw new IllegalArgumentException("invalid size for output buffer: " + outputLength); if (buf == null || buf.capacity() < outputLength) { if (!allowBufferResize) throw new IllegalStateException(String.format("output buffer is not large enough for data: current capacity %d, required %d", buf.capacity(), outputLength)); FileUtils.clean(buf); buf = bufferType.allocate(outputLength); } else { buf.position(0).limit(outputLength); } return buf; }
/** * Ensure {@code buf} is large enough for {@code outputLength}. If not, it is cleaned up and a new buffer is allocated; * else; buffer has it's position/limit set appropriately. * * @param buf buffer to test the size of; may be null, in which case, a new buffer is allocated. * @param outputLength the minimum target size of the buffer * @param allowBufferResize true if resizing (reallocating) the buffer is allowed * @param bufferType on- or off- heap byte buffer * @return {@code buf} if it was large enough, else a newly allocated buffer. */ public static ByteBuffer ensureCapacity(ByteBuffer buf, int outputLength, boolean allowBufferResize, BufferType bufferType) { if (0 > outputLength) throw new IllegalArgumentException("invalid size for output buffer: " + outputLength); if (buf == null || buf.capacity() < outputLength) { if (!allowBufferResize) throw new IllegalStateException(String.format("output buffer is not large enough for data: current capacity %d, required %d", buf.capacity(), outputLength)); FileUtils.clean(buf); buf = bufferType.allocate(outputLength); } else { buf.position(0).limit(outputLength); } return buf; }
protected void writeBuffer(ByteBuffer bb) throws IOException { int originalSize = bb.remaining(); int estimatedSize = compressor.initialCompressedBufferLength(originalSize) + METADATA_SIZE; if (compressionBuffer == null || compressionBuffer.capacity() < estimatedSize) { compressionBuffer = compressor.preferredBufferType().allocate(estimatedSize); } compressionBuffer.clear(); compressionBuffer.position(METADATA_SIZE); compressor.compress(bb, compressionBuffer); int compressedSize = compressionBuffer.position() - METADATA_SIZE; compressionBuffer.rewind(); compressionBuffer.putInt(originalSize); compressionBuffer.putInt(compressedSize); compressionBuffer.rewind(); compressionBuffer.limit(compressedSize + METADATA_SIZE); super.writeBuffer(compressionBuffer); }
protected void writeBuffer(ByteBuffer bb) throws IOException { int originalSize = bb.remaining(); int estimatedSize = compressor.initialCompressedBufferLength(originalSize) + METADATA_SIZE; if (compressionBuffer == null || compressionBuffer.capacity() < estimatedSize) { compressionBuffer = compressor.preferredBufferType().allocate(estimatedSize); } compressionBuffer.clear(); compressionBuffer.position(METADATA_SIZE); compressor.compress(bb, compressionBuffer); int compressedSize = compressionBuffer.position() - METADATA_SIZE; compressionBuffer.rewind(); compressionBuffer.putInt(originalSize); compressionBuffer.putInt(compressedSize); compressionBuffer.rewind(); compressionBuffer.limit(compressedSize + METADATA_SIZE); super.writeBuffer(compressionBuffer); }
public ByteBuffer allocateBuffer(int size) { return metadata.compressor().preferredBufferType().allocate(size); }
public ByteBuffer allocateBuffer(int size) { return metadata.compressor().preferredBufferType().allocate(size); }
public ByteBuffer allocateBuffer(int size) { return metadata.compressor().preferredBufferType().allocate(size); }
protected void writeBuffer(ByteBuffer bb) throws IOException { int originalSize = bb.remaining(); int estimatedSize = compressor.initialCompressedBufferLength(originalSize) + METADATA_SIZE; if (compressionBuffer == null || compressionBuffer.capacity() < estimatedSize) { compressionBuffer = compressor.preferredBufferType().allocate(estimatedSize); } compressionBuffer.clear(); compressionBuffer.position(METADATA_SIZE); compressor.compress(bb, compressionBuffer); int compressedSize = compressionBuffer.position() - METADATA_SIZE; compressionBuffer.rewind(); compressionBuffer.putInt(originalSize); compressionBuffer.putInt(compressedSize); compressionBuffer.rewind(); compressionBuffer.limit(compressedSize + METADATA_SIZE); super.writeBuffer(compressionBuffer); }
public ByteBuffer allocateBuffer(int size) { return metadata.compressor().preferredBufferType().allocate(size); }
public ByteBuffer getThreadLocalReusableBuffer(int size) { ByteBuffer result = reusableBufferHolder.get(); if (result.capacity() < size || BufferType.typeOf(result) != preferredReusableBufferType) { FileUtils.clean(result); result = preferredReusableBufferType.allocate(size); reusableBufferHolder.set(result); } return result; }
public ByteBuffer getThreadLocalReusableBuffer(int size) { ByteBuffer result = reusableBufferHolder.get(); if (result.capacity() < size || BufferType.typeOf(result) != preferredReusableBufferType) { FileUtils.clean(result); result = preferredReusableBufferType.allocate(size); reusableBufferHolder.set(result); } return result; }
public ByteBuffer getThreadLocalReusableBuffer(int size) { ByteBuffer result = reusableBufferHolder.get(); if (result.capacity() < size || BufferType.typeOf(result) != preferredReusableBufferType) { FileUtils.clean(result); result = preferredReusableBufferType.allocate(size); reusableBufferHolder.set(result); } return result; }