Here you can find the source of readBytes(InputStream input)
public static byte[] readBytes(InputStream input) throws IOException
//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[] readBytes(InputStream input) throws IOException { ByteArrayOutputStream output = new ByteArrayOutputStream(); load(input, output);/*ww w . j a v a 2 s . co m*/ return output.toByteArray(); } public static long load(InputStream inputStream, OutputStream outputStream) throws IOException { return load(inputStream, outputStream, 1024); } public static long load(InputStream inputStream, OutputStream outputStream, int buffSize) throws IOException { long size = 0L; int c; byte[] bytes = new byte[buffSize]; while ((c = inputStream.read(bytes, 0, bytes.length)) != -1) { outputStream.write(bytes, 0, c); size = size + c; } outputStream.flush(); // close(outputStream); // close(inputStream); return size; } }