Java Utililty Methods ByteBuffer Slice

List of utility methods to do ByteBuffer Slice

Description

The list of methods to do ByteBuffer Slice are organized into topic(s).

Method

ByteBuffergetSlice(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);
...
ByteBufferpreservingSlice(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;
ByteBufferslice(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;
ByteBufferslice(ByteBuffer buf, int start, int end)
slice
ByteBuffer b = buf.duplicate();
b.position(start);
b.limit(end);
return b.slice();
ByteBufferslice(ByteBuffer data)
slice
if (data.hasRemaining()) {
    byte[] slice = new byte[data.remaining()];
    data.get(slice, 0, data.remaining());
    return ByteBuffer.wrap(slice);
return null;
ByteBufferslice(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;
...
ByteBufferslice(final ByteBuffer buffer, final int position)
slice
final ByteBuffer tmp = buffer.duplicate();
tmp.position(position);
return tmp.slice();
ByteBuffersliceBuffer(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;
...
ByteBuffersliceByteBuffer(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;
ListsliceListBuffersPool(List buffersPool, int smallBufferSize, int buffersCount)
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);
...