Here you can find the source of slice(ByteBuffer buf, int pos, int limit)
public static ByteBuffer slice(ByteBuffer buf, int pos, int limit)
//package com.java2s; //License from project: Apache License import java.nio.ByteBuffer; public class Main { public static ByteBuffer slice(ByteBuffer buf, int pos, int limit) { int oldPos = buf.position(); buf.position(pos);/*from ww w . ja va 2 s . c o m*/ ByteBuffer result = buf.slice(); result.limit(limit - pos); buf.position(oldPos); return result; } }