Here you can find the source of toArray(ByteBuffer buffer)
public static byte[] toArray(ByteBuffer buffer)
//package com.java2s; /**//from ww w . ja va 2s .c o m * 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 byte[] toArray(ByteBuffer buffer) { byte[] result = new byte[buffer.remaining()]; buffer.duplicate().get(result); return result; } public static ByteBuffer duplicate(ByteBuffer bb) { ByteBuffer out = ByteBuffer.allocate(bb.remaining()); out.put(bb.duplicate()); out.flip(); return out; } }