Java tutorial
//package com.java2s; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; public class Main { public static ByteArrayOutputStream inputStreamToByteArrayOutputStream(InputStream inputStream) throws IOException { ByteArrayOutputStream content = new ByteArrayOutputStream(); if (inputStream != null) { int readBytes = 0; byte[] sBuffer = new byte[4096]; while ((readBytes = inputStream.read(sBuffer)) != -1) { content.write(sBuffer, 0, readBytes); } } return content; } }