Here you can find the source of readBytes(InputStream inputStream, int bufSize)
public static byte[] readBytes(InputStream inputStream, int bufSize) throws IOException
//package com.java2s; //License from project: Apache License import java.io.IOException; import java.io.InputStream; public class Main { public static byte[] readBytes(InputStream inputStream, int bufSize) throws IOException { byte[] buf = new byte[bufSize]; byte[] data = new byte[0]; int length = 0; while ((length = inputStream.read(buf)) > 0) { int oldLength = data.length; byte[] temp = new byte[oldLength]; System.arraycopy(data, 0, temp, 0, oldLength); data = new byte[length + oldLength]; System.arraycopy(temp, 0, data, 0, oldLength); System.arraycopy(buf, 0, data, oldLength, length); }/* w w w. ja v a 2 s . c o m*/ return data; } }