Here you can find the source of copyStream(InputStream is, OutputStream os)
public static void copyStream(InputStream is, OutputStream os) throws IOException
//package com.java2s; //License from project: Apache License import java.io.*; public class Main { private static final int DEFAULT_BUFFER_SIZE = 1024; public static void copyStream(InputStream is, OutputStream os) throws IOException { if (is == null) { throw new IllegalArgumentException("InputStream is null"); }//from ww w. jav a2 s . com if (os == null) { throw new IllegalArgumentException("OutputStream is null"); } byte[] b = new byte[DEFAULT_BUFFER_SIZE]; int len = 0; try { while ((len = is.read(b, 0, DEFAULT_BUFFER_SIZE)) != -1) { os.write(b, 0, len); } } finally { is.close(); os.flush(); } } }