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

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

Description

Copies the contents of a stream to another.

License

Open Source License

Parameter

Parameter Description
in the input stream to be copied
out the output stream to which the copy is done

Exception

Parameter Description
IOException if a I/O problem occurs

Declaration

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

Method Source Code

//package com.java2s;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

public class Main {
    /**/*from  w  w  w  . j  av  a2s .  c  om*/
     * Copies the contents of a stream to another.
     * 
     * @param in
     *                the input stream to be copied
     * @param out
     *                the output stream to which the copy is done
     * @throws IOException
     *                 if a I/O problem occurs
     */
    public static void copyStream(final InputStream in, final OutputStream out) throws IOException {
        int bytesRead;
        byte[] b = new byte[10000];
        while ((bytesRead = in.read(b)) != -1) {
            out.write(b, 0, bytesRead);
        }
        out.flush();
    }
}

Related

  1. copyStream(@Nonnull InputStream in, @Nonnull OutputStream out)
  2. copyStream(ByteArrayOutputStream source, ByteArrayOutputStream target)
  3. copyStream(final InputStream in, final OutputStream out)
  4. copyStream(final InputStream in, final OutputStream out, final int bufferSize)
  5. copyStream(final InputStream in, final OutputStream out, int iMax)
  6. copyStream(final InputStream input, final OutputStream output, long count)