Here you can find the source of byteBufferToByteArray(ByteBuffer buf)
public static byte[] byteBufferToByteArray(ByteBuffer buf)
//package com.java2s; //License from project: Apache License import java.nio.ByteBuffer; public class Main { public static byte[] byteBufferToByteArray(ByteBuffer buf) { ByteBuffer str = buf.duplicate(); //System.err.println("Before "+str); str.rewind();/*from ww w .j av a 2s . c o m*/ //str.flip(); //System.err.println("After "+str); byte[] dst = new byte[str.limit()]; str.get(dst); return dst; } }