Here you can find the source of copyStream(OutputStream outStream, InputStream inStream)
public static void copyStream(OutputStream outStream, InputStream inStream) 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 ww w. j a v a 2s. com*/ * Copies specified input stream to specified output stream. */ public static void copyStream(OutputStream outStream, InputStream inStream) throws IOException { try { byte[] bytes = new byte[1024]; int count = inStream.read(bytes); while (count > 0) { outStream.write(bytes, 0, count); count = inStream.read(bytes); } } catch (IOException e) { throw e; } finally { inStream.close(); } } }