Here you can find the source of toBytes(ByteBuffer value)
static public byte[] toBytes(ByteBuffer value)
//package com.java2s; //License from project: Open Source License import java.nio.ByteBuffer; public class Main { /**/*from ww w .j a va 2s .c om*/ * Convert a ByteBuffer to a byte[] * ByteBuffer is reset to its original state. */ static public byte[] toBytes(ByteBuffer value) { byte[] result = null; if (value != null && value.remaining() > 0) { result = new byte[value.remaining()]; value.mark(); value.get(result); value.reset(); } return result; } }