Here you can find the source of readBytes(InputStream is)
public static byte[] readBytes(InputStream is) throws IOException
//package com.java2s; //The contents of this file are subject to the "Simplified BSD License" (the "License"); import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; public class Main { public static byte[] readBytes(InputStream is) throws IOException { ByteArrayOutputStream bs = new ByteArrayOutputStream(); @SuppressWarnings("unused") long size = copyStream(is, bs); return bs.toByteArray(); }//from w ww .j a v a2s . c o m public static long copyStream(InputStream is, OutputStream os) throws IOException { byte[] buf = new byte[1024]; int len; long size = 0; while ((len = is.read(buf)) > 0) { os.write(buf, 0, len); size += len; } return size; } }