Here you can find the source of sliceListBuffersPool(List
public static <E extends Comparable<E>> List<ByteBuffer> sliceListBuffersPool(List<ByteBuffer> buffersPool, int smallBufferSize, int buffersCount)
//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); } }