Here you can find the source of inputStreamToByte(InputStream is)
public static byte[] inputStreamToByte(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[] inputStreamToByte(InputStream is) throws IOException { ByteArrayOutputStream bytestream = new ByteArrayOutputStream(); int ch;/* ww w .j a v a 2 s . co m*/ while ((ch = is.read()) != -1) { bytestream.write(ch); } byte data[] = bytestream.toByteArray(); bytestream.close(); return data; } }