Here you can find the source of getAsBytes(List
public static byte[] getAsBytes(List<ByteBuffer> buffers)
//package com.java2s; //License from project: Apache License import java.nio.ByteBuffer; import java.util.List; public class Main { /**/* w ww . j av a 2 s . c o m*/ * Copies the contents of the buffers into a single byte[] */ //TODO: not tested public static byte[] getAsBytes(List<ByteBuffer> buffers) { //find total size int size = 0; for (ByteBuffer buffer : buffers) { size += buffer.remaining(); } byte[] arr = new byte[size]; int offset = 0; for (ByteBuffer buffer : buffers) { int len = buffer.remaining(); buffer.get(arr, offset, len); offset += len; } return arr; } }