Here you can find the source of readBytes(InputStream in, byte[] buffer)
public static byte[] readBytes(InputStream in, byte[] buffer) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; public class Main { public static byte[] readBytes(InputStream in, byte[] buffer) throws IOException { ByteArrayOutputStream out = new ByteArrayOutputStream(); int read; while (0 <= (read = in.read(buffer))) { out.write(buffer, 0, read);/*from ww w . j av a 2s .c om*/ } return out.toByteArray(); } }