Here you can find the source of copyStream(InputStream in, OutputStream out)
public static void copyStream(InputStream in, OutputStream out) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.*; public class Main { public static final int BUFSIZ = 0x2000; public static void copyStream(InputStream in, OutputStream out) throws IOException { byte[] buffer = new byte[BUFSIZ]; for (;;) { int size = in.read(buffer); if (size <= 0) break; out.write(buffer, 0, size);/*from w w w . j a v a2s . c o m*/ } } public static void copyStream(InputStream src, OutputStream dst, long length) throws IOException { byte[] buffer = new byte[BUFSIZ]; for (;;) { int size = src.read(buffer); if (size < 0) break; dst.write(buffer, 0, size); length -= size; if (length <= 0) break; } } }