Here you can find the source of getBytesFromInputStream(InputStream is)
public static byte[] getBytesFromInputStream(InputStream is) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.*; public class Main { public static byte[] getBytesFromInputStream(InputStream is) throws IOException { ByteArrayOutputStream buffer = new ByteArrayOutputStream(); int nRead; byte[] data = new byte[16384]; while ((nRead = is.read(data, 0, data.length)) != -1) { buffer.write(data, 0, nRead); }/*from w w w . j a v a 2 s . co m*/ buffer.flush(); return buffer.toByteArray(); } }