Here you can find the source of readBytes(InputStream inputStream)
public static byte[] readBytes(InputStream inputStream) throws IOException
//package com.java2s; //it under the terms of the GNU Affero General Public License as published by import java.io.*; public class Main { public static byte[] readBytes(InputStream inputStream) throws IOException { ByteArrayOutputStream byteOut = new ByteArrayOutputStream(); copyStream(inputStream, byteOut); return byteOut.toByteArray(); }/*from ww w .j a va2s. c om*/ public static void copyStream(InputStream in, OutputStream out) throws IOException { byte[] buffer = new byte[4096]; while (true) { int bytesRead = in.read(buffer); if (bytesRead == -1) { break; } out.write(buffer, 0, bytesRead); } } }