Here you can find the source of readAll(InputStream in)
public static byte[] readAll(InputStream in) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.*; public class Main { public static byte[] readAll(InputStream in) throws IOException { ByteArrayOutputStream out = new ByteArrayOutputStream(Math.max(512, in.available())); byte[] buffer = new byte[1024 * 4]; int n;/*from w w w . j a v a2 s .c o m*/ while ((n = in.read(buffer)) != -1) { out.write(buffer, 0, n); } out.flush(); return out.toByteArray(); } }