Here you can find the source of copyStream(InputStream in, OutputStream out)
static public int copyStream(InputStream in, OutputStream out) throws IOException
//package com.java2s; //License from project: Apache License import java.io.*; public class Main { static public int copyStream(InputStream in, OutputStream out) throws IOException { int length = 0; byte[] buffer = new byte[1024]; for (int read = in.read(buffer); read != -1; read = in.read(buffer)) { out.write(buffer, 0, read);/*w w w .j ava2s . c o m*/ length += read; } out.flush(); out.close(); return length; } }