Java InputStream to OutputStream copyStreams(final InputStream in, final OutputStream out)

Here you can find the source of copyStreams(final InputStream in, final OutputStream out)

Description

Copies all bytes from inputstream to outputstream.

License

Open Source License

Declaration

public static final void copyStreams(final InputStream in, final OutputStream out) throws IOException 

Method Source Code

//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);
        }
    }
}

Related

  1. copyStreamContent(InputStream inputStream, OutputStream outputStream)
  2. copyStreamFully(InputStream in, OutputStream out, int length)
  3. copyStreamIoe(final InputStream is, final OutputStream os)
  4. copyStreamNoClose(InputStream in, OutputStream out)
  5. copyStreamPortion(java.io.InputStream inputStream, java.io.OutputStream outputStream, int portionSize, int bufferSize)
  6. copyStreams(final InputStream input, final OutputStream output)
  7. copyStreams(InputStream from, OutputStream to, int blockSize)
  8. copyStreams(InputStream in, OutputStream out)
  9. copyStreams(InputStream in, OutputStream out)