Here you can find the source of readBytes(ByteBuffer buffer)
public static byte[] readBytes(ByteBuffer buffer)
//package com.java2s; //License from project: Apache License import java.nio.ByteBuffer; public class Main { /**/* w w w .ja v a 2 s . com*/ * Read the given byte buffer into a byte array */ public static byte[] readBytes(ByteBuffer buffer) { return readBytes(buffer, 0, buffer.limit()); } /** * Read a byte array from the given offset and size in the buffer */ public static byte[] readBytes(ByteBuffer buffer, int offset, int size) { byte[] dest = new byte[size]; if (buffer.hasArray()) { System.arraycopy(buffer.array(), buffer.arrayOffset() + offset, dest, 0, size); } else { buffer.mark(); buffer.get(dest); buffer.reset(); } return dest; } }