Here you can find the source of readAllBytesToOutput(InputStream is, OutputStream output)
private static int readAllBytesToOutput(InputStream is, OutputStream output) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; public class Main { private static final int TEMP_BUFFER_DEFAULT_LENGTH = 2048; private static int readAllBytesToOutput(InputStream is, OutputStream output) throws IOException { //ByteArrayOutputStream output = new ByteArrayOutputStream(); byte[] tempBuffer = new byte[TEMP_BUFFER_DEFAULT_LENGTH]; int readed; int totalRead = 0; while (true) { readed = is.read(tempBuffer, 0, TEMP_BUFFER_DEFAULT_LENGTH); if (readed < 0) { //no more to read break; }/* w w w. j a v a2 s. c o m*/ totalRead += readed; if (readed != 0) { output.write(tempBuffer, 0, readed); output.flush(); } } return totalRead; } }