Here you can find the source of copyStreams(InputStream in, OutputStream out)
public static void copyStreams(InputStream in, OutputStream out) throws IOException
//package com.java2s; //License from project: Apache License import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; public class Main { /**//from www.ja v a 2 s . com * Copy all data from in to out in 4096 byte chunks. */ public static void copyStreams(InputStream in, OutputStream out) throws IOException { if (in == null || out == null) { throw new IllegalArgumentException(); } final byte[] buffer = new byte[4096]; int len; while (-1 != (len = in.read(buffer, 0, buffer.length))) { out.write(buffer, 0, len); } } }