Here you can find the source of copyStream(InputStream is, OutputStream os, boolean closeInput)
public static void copyStream(InputStream is, OutputStream os, boolean closeInput) 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 is, OutputStream os, boolean closeInput) throws IOException { try {// w ww . j a v a 2s .c om byte[] bytes = new byte[4096]; int numBytes; while ((numBytes = is.read(bytes)) != -1) { os.write(bytes, 0, numBytes); } } finally { if (closeInput) { is.close(); } } } }