Here you can find the source of copyStreamBytes(InputStream is)
static byte[] copyStreamBytes(InputStream is) throws IOException
//package com.java2s; // License & terms of use: http://www.unicode.org/copyright.html#License import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; public class Main { static byte[] copyStreamBytes(InputStream is) throws IOException { byte[] buffer = new byte[1024]; ByteArrayOutputStream bos = new ByteArrayOutputStream(); int len;//from w ww .j a va2 s. c o m while ((len = is.read(buffer, 0, buffer.length)) >= 0) { bos.write(buffer, 0, len); } return bos.toByteArray(); } }