Here you can find the source of readToByteBuffer(InputStream inStream)
static ByteBuffer readToByteBuffer(InputStream inStream) throws IOException
//package com.java2s; //License from project: LGPL import java.io.*; import java.nio.ByteBuffer; public class Main { private static final int bufferSize = 0x20000; static ByteBuffer readToByteBuffer(InputStream inStream) throws IOException { byte[] buffer = new byte[bufferSize]; ByteArrayOutputStream outStream = new ByteArrayOutputStream(bufferSize); int read; while (true) { read = inStream.read(buffer); if (read == -1) break; outStream.write(buffer, 0, read); }//from ww w. ja va 2 s . c o m ByteBuffer byteData = ByteBuffer.wrap(outStream.toByteArray()); return byteData; } }