Here you can find the source of copyStream(InputStream from, OutputStream to)
public static long copyStream(InputStream from, OutputStream to) throws IOException
//package com.java2s; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; public class Main { public static long copyStream(InputStream from, OutputStream to) throws IOException { long total = 0; byte[] buf = new byte[2048]; while (true) { int r = from.read(buf); if (r == -1) { break; }//w w w .ja v a2s . c o m to.write(buf, 0, r); total += r; } return total; } }