Here you can find the source of getBytes(InputStream is, int max_len)
public static byte[] getBytes(InputStream is, int max_len) throws IOException
//package com.java2s; //License from project: Apache License import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; public class Main { public static byte[] getBytes(InputStream is, int max_len) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(max_len); for (int i = 0, b = is.read(); b >= 0 && i < max_len; b = is.read(), ++i) baos.write(b);/* ww w.j a v a 2 s . c o m*/ return baos.toByteArray(); } public static byte[] getBytes(InputStream is) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); for (int b = is.read(); b >= 0; b = is.read()) baos.write(b); return baos.toByteArray(); } }