Here you can find the source of copyStream(final InputStream inputStream, final OutputStream outputStream)
public static int copyStream(final InputStream inputStream, final OutputStream outputStream) throws IOException
//package com.java2s; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; public class Main { static final int BUFFER = 8 * 1024; public static int copyStream(final InputStream inputStream, final OutputStream outputStream) throws IOException { int result = 0; final byte[] buf = new byte[BUFFER]; for (;;) { final int numRead = inputStream.read(buf); if (numRead == -1) { break; }/*from w w w .j av a 2 s .com*/ outputStream.write(buf, 0, numRead); result += numRead; } outputStream.flush(); return result; } }