Java ByteBuffer Slice sliceListBuffersPool(List buffersPool, int smallBufferSize, int buffersCount)

Here you can find the source of sliceListBuffersPool(List buffersPool, int smallBufferSize, int buffersCount)

Description

slice List Buffers Pool

License

Open Source License

Declaration

public static <E extends Comparable<E>> List<ByteBuffer> sliceListBuffersPool(List<ByteBuffer> buffersPool,
            int smallBufferSize, int buffersCount) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.nio.ByteBuffer;

import java.util.ArrayList;

import java.util.List;

public class Main {
    public static <E extends Comparable<E>> List<ByteBuffer> sliceListBuffersPool(List<ByteBuffer> buffersPool,
            int smallBufferSize, int buffersCount) {
        List<ByteBuffer> smallBuffers = new ArrayList<>();
        for (ByteBuffer bigBuffer : buffersPool) {
            bigBuffer.rewind();//from  ww  w  .  j a  v  a  2 s .co  m

            while (bigBuffer.capacity() - bigBuffer.position() > smallBufferSize) {
                if (smallBuffers.size() == buffersCount) {
                    return smallBuffers;
                }
                bigBuffer.limit(bigBuffer.position() + smallBufferSize);
                smallBuffers.add(bigBuffer.slice());
                bigBuffer.position(bigBuffer.limit());
            }
            if (smallBuffers.size() == buffersCount) {
                return smallBuffers;
            }
        }
        throw new IndexOutOfBoundsException(" " + smallBuffers.size() + " " + smallBufferSize);
    }
}

Related

  1. slice(ByteBuffer data)
  2. slice(final ByteBuffer buffer, final int offset, final int length)
  3. slice(final ByteBuffer buffer, final int position)
  4. sliceBuffer(ByteBuffer byteBuffer, int start, int end)
  5. sliceByteBuffer(ByteBuffer buffer, int position, int length)
  6. slicePosition(ByteBuffer base, int position)
  7. sliceToByte(ByteBuffer val, int offset, int length)