Here you can find the source of readAll(InputStream in)
public static byte[] readAll(InputStream in)
//package com.java2s; 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) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); copyTo(in, baos);//w ww .j a v a 2 s . co m return baos.toByteArray(); } public static void copyTo(InputStream in, OutputStream out) { try { byte[] arr = new byte[1024]; int read; while ((read = in.read(arr)) != -1) { out.write(arr, 0, read); } } catch (IOException e) { throw new RuntimeException(e); } } }