Here you can find the source of copyStream(InputStream input, OutputStream output, int length)
public static void copyStream(InputStream input, OutputStream output, int length) 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 { public static void copyStream(InputStream input, OutputStream output, int length) throws IOException { byte[] buffer = new byte[length]; int remaining = length; int bytesRead; while ((bytesRead = input.read(buffer, 0, remaining)) != -1 && remaining > 0) { output.write(buffer, 0, bytesRead); remaining -= bytesRead;/*from w w w . ja v a 2 s .c o m*/ } } }