Here you can find the source of inputStreamToByteArray(InputStream is)
public static byte[] inputStreamToByteArray(InputStream is) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.*; public class Main { public static byte[] inputStreamToByteArray(InputStream is) throws IOException { ByteArrayOutputStream byteStream = new ByteArrayOutputStream(); try {//from w ww . j a v a2 s . c o m int ch = -1; while ((ch = is.read()) != -1) { byteStream.write(ch); } return byteStream.toByteArray(); } finally { byteStream.close(); } } }