Java tutorial
//package com.java2s; import java.io.*; public class Main { public static byte[] readStream(InputStream in) throws IOException { byte[] ret = null; if (in != null) { ByteArrayOutputStream bout = new ByteArrayOutputStream(); byte[] buf = new byte[128]; int len; while (true) { len = in.read(buf); if (len == -1) { break; } bout.write(buf, 0, len); } buf = null; ret = bout.toByteArray(); } return ret; } }