Here you can find the source of copy(InputStream in, OutputStream out)
public static void copy(InputStream in, OutputStream out) throws IOException
//package com.java2s; //License from project: Apache License import java.io.*; import java.nio.file.Files; import java.nio.file.Path; public class Main { private static final int IO_BUFFER_SIZE = 8 * 1024; public static void copy(InputStream in, OutputStream out) throws IOException { byte[] b = new byte[IO_BUFFER_SIZE]; int read; while ((read = in.read(b)) != -1) { out.write(b, 0, read);//from w ww . j a v a 2s .c o m } } public static byte[] read(InputStream in) throws IOException { ByteArrayOutputStream out = new ByteArrayOutputStream(); copy(in, out); out.close(); return out.toByteArray(); } public static void write(Path path, String string) throws IOException { PrintWriter out = null; try { out = new PrintWriter(Files.newOutputStream(path)); out.write(string); } finally { if (out != null) { out.close(); } } } }