Here you can find the source of copyStream(InputStream is)
public static byte[] copyStream(InputStream is) throws IOException
//package com.java2s; //License from project: Apache License import java.io.*; public class Main { public static byte[] copyStream(InputStream is) throws IOException { ByteArrayOutputStream buffer = new ByteArrayOutputStream(); int nRead; byte[] data = new byte[64 * 1024]; while ((nRead = is.read(data, 0, data.length)) != -1) { buffer.write(data, 0, nRead); }/*from ww w.java 2s.c o m*/ buffer.flush(); return buffer.toByteArray(); } }