Here you can find the source of readInputStream(InputStream input)
public static ByteBuffer readInputStream(InputStream input) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.IOException; import java.io.InputStream; import java.nio.ByteBuffer; public class Main { public static final int BUFFER_SIZE = 16384; public static ByteBuffer readInputStream(InputStream input) throws IOException { byte[] buf = new byte[BUFFER_SIZE]; int idx = 0; for (;;) { int rd = input.read(buf, idx, buf.length - idx); if (rd < 0) break; idx += rd;//from w w w .j a v a 2 s .co m if (idx == buf.length) { byte[] nbuf = new byte[idx * 2]; System.arraycopy(buf, 0, nbuf, 0, idx); buf = nbuf; } } return ByteBuffer.wrap(buf, 0, idx); } }