Here you can find the source of readBytes(InputStream inputStream)
public static byte[] readBytes(InputStream inputStream) throws IOException
//package com.java2s; // under the terms of the Eclipse Public License v1.0 which accompanies import java.io.BufferedInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; public class Main { public static byte[] readBytes(InputStream inputStream) throws IOException { BufferedInputStream bufferedInputStream = new BufferedInputStream( inputStream);//from www .j a va 2 s . c o m ByteArrayOutputStream output = new ByteArrayOutputStream(); byte[] array = new byte[1024]; while (true) { int len = bufferedInputStream.read(array); if (len == -1) { break; } output.write(array, 0, len); } return output.toByteArray(); } }