Here you can find the source of duplicate(ByteBuffer bb)
public static ByteBuffer duplicate(ByteBuffer bb)
//package com.java2s; /**//w w w . j a va 2 s . c om * This class is part of JCodec ( www.jcodec.org ) This software is distributed * under FreeBSD License * * @author The JCodec project * */ import java.nio.ByteBuffer; public class Main { public static ByteBuffer duplicate(ByteBuffer bb) { ByteBuffer out = ByteBuffer.allocate(bb.remaining()); out.put(bb.duplicate()); out.flip(); return out; } }