Here you can find the source of readAll(InputStream in)
public static byte[] readAll(InputStream in) throws IOException
//package com.java2s; //License from project: Apache License import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; public class Main { public static byte[] readAll(InputStream in) throws IOException { ByteArrayOutputStream bout = new ByteArrayOutputStream(); transferStream(in, bout);//from w w w . j a va 2 s . com byte[] bytes = bout.toByteArray(); bout.close(); return bytes; } public static void transferStream(InputStream in, OutputStream out) throws IOException { byte[] bytes = new byte[1024]; int numRead = in.read(bytes); while (numRead != -1) { out.write(bytes, 0, numRead); numRead = in.read(bytes); } } public static void close(InputStream in) { try { in.close(); } catch (IOException e) { } } public static void close(OutputStream out) { try { out.close(); } catch (IOException e) { } } }