Here you can find the source of copyStream(InputStream src, OutputStream dest)
public static boolean copyStream(InputStream src, OutputStream dest)
//package com.java2s; import java.io.InputStream; import java.io.OutputStream; import java.io.IOException; public class Main { private static int COPYSTREAM_BUFFER_SIZE = 2 * 1024; public static boolean copyStream(InputStream src, OutputStream dest) { byte[] buffer = new byte[COPYSTREAM_BUFFER_SIZE]; try {/*w ww .j a v a 2 s . com*/ int size; while ((size = src.read(buffer)) != -1) { dest.write(buffer, 0, size); } } catch (IOException e) { return false; } return true; } }