Here you can find the source of readAllFromStream(InputStream is)
public static byte[] readAllFromStream(InputStream is) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.*; public class Main { public static byte[] readAllFromStream(InputStream is) throws IOException { DataInputStream dis = new DataInputStream(is); byte[] buffer = new byte[4096]; int totalBytesRead = 0, bytesRead; while ((bytesRead = dis.read(buffer, totalBytesRead, buffer.length - totalBytesRead)) >= 0) { if (totalBytesRead + bytesRead >= buffer.length) { byte[] oldBuffer = buffer; buffer = new byte[oldBuffer.length * 2]; System.arraycopy(oldBuffer, 0, buffer, 0, oldBuffer.length); }/*w w w .ja v a 2 s .c o m*/ totalBytesRead += bytesRead; } byte[] ret = new byte[totalBytesRead]; System.arraycopy(buffer, 0, ret, 0, totalBytesRead); return ret; } }