Here you can find the source of toArray(ByteBuffer buffer)
public static byte[] toArray(ByteBuffer buffer)
//package com.java2s; //License from project: Apache License import java.nio.ByteBuffer; public class Main { public static byte[] toArray(ByteBuffer buffer) { byte[] arr = new byte[buffer.limit()]; buffer.get(arr);// w ww. j a v a 2s . co m return arr; } }