Here you can find the source of copyStream(InputStream source, OutputStream dest)
private static void copyStream(InputStream source, OutputStream dest) throws IOException
//package com.java2s; /*/* w w w . j a v a 2 s . c om*/ * Copyright 2015, Yahoo Inc. * Copyrights licensed under the Apache 2.0 License. * See the accompanying LICENSE file for terms. */ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; public class Main { /** * Copy a stream from source to destination */ private static void copyStream(InputStream source, OutputStream dest) throws IOException { int bytes; byte[] buffer; int BUFFER_SIZE = 1024; buffer = new byte[BUFFER_SIZE]; while ((bytes = source.read(buffer)) > 0) { dest.write(buffer, 0, bytes); } } }