Java tutorial
//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[] readStreamContent(InputStream stream) { ByteArrayOutputStream bos = new ByteArrayOutputStream(); byte[] buf = new byte[1024]; while (true) { try { int read = stream.read(buf); if (read == -1) break; bos.write(buf, 0, read); } catch (IOException e) { return null; } } return bos.toByteArray(); } }