Here you can find the source of writeStreamToArray(InputStream stream)
public static byte[] writeStreamToArray(InputStream stream) 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[] writeStreamToArray(InputStream stream) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); byte[] buffer = new byte[1024]; int length = 0; while ((length = stream.read(buffer)) != -1) baos.write(buffer, 0, length); return baos.toByteArray(); }//from ww w.jav a2 s .c o m }