Here you can find the source of clone(ByteBuffer original)
public static ByteBuffer clone(ByteBuffer original)
//package com.java2s; //License from project: Apache License import java.nio.*; public class Main { public static ByteBuffer clone(ByteBuffer original) { ByteBuffer clone = ByteBuffer.allocate(original.capacity()); original.rewind();//copy from the beginning clone.put(original);// w w w . ja va2 s. com original.rewind(); clone.flip(); return clone; } }