Here you can find the source of copy(InputStream in, OutputStream out)
public static long copy(InputStream in, OutputStream out) throws IOException
//package com.java2s; import java.io.Closeable; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; public class Main { private static final int BUFF_SIZE = 16 * 1024; /**//from w ww.j a v a2s .c o m * Copies the content of the InputStream to the OutputStream. * Both streams are closed automatically. */ public static long copy(InputStream in, OutputStream out) throws IOException { long filesize = 0; try { byte[] buffer = new byte[BUFF_SIZE]; int bytesRead = in.read(buffer); while (bytesRead != -1) { filesize += bytesRead; out.write(buffer, 0, bytesRead); bytesRead = in.read(buffer); } } finally { closeQuitely(out); closeQuitely(in); } return filesize; } public static void closeQuitely(Closeable c) { if (c == null) return; try { c.close(); } catch (IOException e) { // ignore } } }