Here you can find the source of copyStream(final InputStream is, final OutputStream os)
public static void copyStream(final InputStream is, final OutputStream os) 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(final InputStream is, final OutputStream os) throws IOException { byte[] buf = new byte[16 * 1024]; while (true) { int len = is.read(buf); if (len <= 0) { break; }//from w ww. j av a 2s. com os.write(buf, 0, len); } } public static void copyStream(final InputStream is, final OutputStream os, final boolean close) throws IOException { try { try { copyStream(is, os); } finally { if (close) { os.close(); } } } finally { if (close) { is.close(); } } } }