Here you can find the source of cloneByteBuffer(ByteBuffer buf)
public static ByteBuffer cloneByteBuffer(ByteBuffer buf)
//package com.java2s; //License from project: Open Source License import java.nio.ByteBuffer; public class Main { public static ByteBuffer cloneByteBuffer(ByteBuffer buf) { ByteBuffer ret = ByteBuffer.allocate(buf.limit() - buf.position()); ret.put(buf);//from ww w .j a va2s . c om ret.flip(); buf.flip(); return ret; } }