Here you can find the source of toByteArray(ByteBuffer buffer)
public static byte[] toByteArray(ByteBuffer buffer)
//package com.java2s; //License from project: Apache License import java.nio.ByteBuffer; import java.util.Map; public class Main { public static byte[] toByteArray(ByteBuffer buffer) { byte[] ret = new byte[buffer.remaining()]; buffer.get(ret, 0, ret.length);//from w w w.ja v a 2 s . co m return ret; } public static <S, T> T get(Map<S, T> m, S key, T def) { T ret = m.get(key); if (ret == null) { ret = def; } return ret; } }