Here you can find the source of copy(ByteBuffer buf)
static ByteBuffer copy(ByteBuffer buf)
//package com.java2s; //License from project: Open Source License import java.nio.ByteBuffer; public class Main { static ByteBuffer copy(ByteBuffer buf) { ByteBuffer ret;/* w ww . j a va 2s . c o m*/ if (buf.isDirect()) { ret = buf.allocateDirect(buf.remaining()); } else { ret = buf.allocate(buf.remaining()); } ret.put(buf.duplicate()); ret.clear(); return ret; } }