List of utility methods to do ByteBuffer Slice
ByteBuffer | getSlice(ByteBuffer bb, int offset, int length) Returns the subset of a byte buffer, using the given offset and length. if (length == 0) { return EMPTY; ByteOrder order = bb.order(); bb = bb.duplicate(); bb.position(offset); if (length > 0) { bb.limit(offset + length); ... |
ByteBuffer | preservingSlice(final ByteBuffer byteBuffer, final int position, final int limit) Slice a portion of the ByteBuffer while preserving the buffers position and limit. final int savedPosition = byteBuffer.position(); final int savedLimit = byteBuffer.limit(); byteBuffer.limit(limit).position(position); final ByteBuffer result = byteBuffer.slice(); byteBuffer.limit(savedLimit).position(savedPosition); return result; |
ByteBuffer | slice(ByteBuffer buf, int pos, int limit) slice int oldPos = buf.position(); buf.position(pos); ByteBuffer result = buf.slice(); result.limit(limit - pos); buf.position(oldPos); return result; |
ByteBuffer | slice(ByteBuffer buf, int start, int end) slice ByteBuffer b = buf.duplicate();
b.position(start);
b.limit(end);
return b.slice();
|
ByteBuffer | slice(ByteBuffer data) slice if (data.hasRemaining()) { byte[] slice = new byte[data.remaining()]; data.get(slice, 0, data.remaining()); return ByteBuffer.wrap(slice); return null; |
ByteBuffer | slice(final ByteBuffer buffer, final int offset, final int length) Slices a part of the specified ByteBuffer into a new byte buffer and returns it. final int oldPosition = buffer.position(); final int oldLimit = buffer.limit(); buffer.position(offset); buffer.limit(offset + length); final ByteBuffer slice = buffer.slice(); buffer.position(oldPosition); buffer.limit(oldLimit); return slice; ... |
ByteBuffer | slice(final ByteBuffer buffer, final int position) slice final ByteBuffer tmp = buffer.duplicate(); tmp.position(position); return tmp.slice(); |
ByteBuffer | sliceBuffer(ByteBuffer byteBuffer, int start, int end) slice Buffer int pos = byteBuffer.position(); int limit = byteBuffer.limit(); byteBuffer.position(start); byteBuffer.limit(end); ByteBuffer result = byteBuffer.slice(); byteBuffer.limit(limit); byteBuffer.position(pos); return result; ... |
ByteBuffer | sliceByteBuffer(ByteBuffer buffer, int position, int length) Creates a new ByteBuffer sliced from a given ByteBuffer. ByteBuffer slicedBuffer = ((ByteBuffer) buffer.duplicate().position(position)).slice();
slicedBuffer.limit(length);
return slicedBuffer;
|
List | sliceListBuffersPool(List slice List Buffers Pool List<ByteBuffer> smallBuffers = new ArrayList<>(); for (ByteBuffer bigBuffer : buffersPool) { bigBuffer.rewind(); while (bigBuffer.capacity() - bigBuffer.position() > smallBufferSize) { if (smallBuffers.size() == buffersCount) { return smallBuffers; bigBuffer.limit(bigBuffer.position() + smallBufferSize); ... |