/** * Allocate buffer using set buffer type and buffer size. * * @return allocated ByteBuffer */ public ByteBuffer allocateBuffer() { return bufferType.allocate(bufferSize); }
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; }
/** * 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 * @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 = buf != null ? BufferType.typeOf(buf) : BufferType.ON_HEAP; return ensureCapacity(buf, outputLength, allowBufferResize, bufferType); }
/** * 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 * @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 = buf != null ? BufferType.typeOf(buf) : BufferType.ON_HEAP; return ensureCapacity(buf, outputLength, allowBufferResize, bufferType); }
/** * Allocate buffer using set buffer type and buffer size. * * @return allocated ByteBuffer */ public ByteBuffer allocateBuffer() { return bufferType.allocate(bufferSize); }
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; }
/** * 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 * @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 = buf != null ? BufferType.typeOf(buf) : BufferType.ON_HEAP; return ensureCapacity(buf, outputLength, allowBufferResize, bufferType); }
/** * Allocate buffer using set buffer type and buffer size. * * @return allocated ByteBuffer */ public ByteBuffer allocateBuffer() { return bufferType.allocate(bufferSize); }
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; }
/** * 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 * @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 = buf != null ? BufferType.typeOf(buf) : BufferType.ON_HEAP; return ensureCapacity(buf, outputLength, allowBufferResize, bufferType); }
/** * Allocate buffer using set buffer type and buffer size. * * @return allocated ByteBuffer */ public ByteBuffer allocateBuffer() { 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 * @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 = buf != null ? BufferType.typeOf(buf) : BufferType.ON_HEAP; return ensureCapacity(buf, outputLength, allowBufferResize, bufferType); }
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; }
/** * 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; }