Here you can find the source of copyStream(InputStream is, OutputStream os)
public static void copyStream(InputStream is, OutputStream os) throws IOException
//package com.java2s; /**/* ww w.j a va 2 s . c o m*/ * Copyright (c) 2006-2009, Cloudsmith Inc. * The code, documentation and other materials contained herein have been * licensed under the Eclipse Public License - v 1.0 by the copyright holder * listed above, as the Initial Contributor under such license. The text of * such license is available at www.eclipse.org. */ import java.io.Closeable; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; public class Main { public static void copyStream(InputStream is, OutputStream os) throws IOException { copyStream(is, os, true, true); } public static void copyStream(InputStream is, OutputStream os, boolean closeInput, boolean closeOutput) throws IOException { byte[] buffer = new byte[1024]; int len; try { while ((len = is.read(buffer)) != -1) { os.write(buffer, 0, len); } } finally { try { if (closeInput) is.close(); } catch (IOException e) { // ignore } if (closeOutput) os.close(); } } /** * @param is */ public static void close(Closeable is) { if (is != null) try { is.close(); } catch (IOException e) { // ignore } } }