Here you can find the source of inputStream2ByteArray(InputStream input)
public static byte[] inputStream2ByteArray(InputStream input) throws IOException
//package com.java2s; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; public class Main { public static byte[] inputStream2ByteArray(InputStream input) throws IOException { ByteArrayOutputStream output = new ByteArrayOutputStream(); byte[] buffer = new byte[4096]; int n = 0; while (-1 != (n = input.read(buffer))) { output.write(buffer, 0, n);//from w w w . ja v a 2 s . c om } return output.toByteArray(); } }