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.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; public class Main { public static byte[] inputStreamToByteArray(InputStream is) throws IOException { ByteArrayOutputStream os = null; try {//from w w w .java 2s .c om os = new ByteArrayOutputStream(); byte[] buffer = new byte[0xFFFF]; for (int len; (len = is.read(buffer)) != -1;) { os.write(buffer, 0, len); } os.flush(); return os.toByteArray(); } catch (IOException ex) { return null; } finally { if (os != null) { os.close(); } } } }