Here you can find the source of copyTo(ByteBuffer original, ByteBuffer copy)
public static void copyTo(ByteBuffer original, ByteBuffer copy)
//package com.java2s; //License from project: Open Source License import java.nio.ByteBuffer; public class Main { public static void copyTo(ByteBuffer original, ByteBuffer copy) { original.rewind();// copy from the beginning copy.put(original);/*w w w . jav a 2 s . c o m*/ original.rewind(); // copy.flip(); } }