Here you can find the source of copyStream(InputStream input, OutputStream output, int bufferSize)
public static void copyStream(InputStream input, OutputStream output, int bufferSize) throws Exception
//package com.java2s; import java.io.InputStream; import java.io.OutputStream; public class Main { public static void copyStream(InputStream input, OutputStream output, int bufferSize) throws Exception { try {/*from ww w.j a va 2 s .c o m*/ byte[] buf = new byte[bufferSize]; int len; while ((len = input.read(buf)) > 0) { output.write(buf, 0, len); } } finally { if (input != null) { input.close(); } if (output != null) { output.flush(); output.close(); } } } }