Here you can find the source of copyStreams(final InputStream in, final OutputStream out)
public static final void copyStreams(final InputStream in, final OutputStream out) throws IOException
//package com.java2s; /* Copyright 2012 InterCommIT b.v. * * This file is part of the "BasicJspWs" project hosted on https://github.com/intercommit/basicjspws * * BasicJspWs is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * any later version.// www .j av a 2 s . c o m * * BasicJspWs is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with BasicJspWs. If not, see <http://www.gnu.org/licenses/>. * */ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; public class Main { /** Copies all bytes from inputstream to outputstream. Does NOT close the streams. */ public static final void copyStreams(final InputStream in, final OutputStream out) throws IOException { copyStreams(in, out, new byte[16384]); } /** Copies all bytes from inputstream to outputstream using the provided buffer (must have size > 0). * Use this when many copy-operations are done in a thread-safe manner to save memory. Does NOT close the streams. */ public static final void copyStreams(final InputStream in, final OutputStream out, final byte[] buf) throws IOException { // Transfer bytes from in to out int len; while ((len = in.read(buf)) > 0) { out.write(buf, 0, len); } } }