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

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

Description

Copy bytes from input to output stream, leaving out stream open

License

Open Source License

Parameter

Parameter Description
in input stream
out output stream

Exception

Parameter Description
IOException on error

Declaration

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

Method Source Code

//package com.java2s;
//License from project: Open Source License 

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

import java.io.OutputStream;

public class Main {
    /**//  w  ww .  j  ava2  s.c  om
     * Copy bytes from input to output stream, leaving out stream open
     * 
     * @param in
     *            input stream
     * @param out
     *            output stream
     * @throws IOException
     *             on error
     */
    public static void copyStream(InputStream in, OutputStream out) throws IOException {
        if (in == null) {
            throw new NullPointerException("Input stream is null");
        }

        if (out == null) {
            throw new NullPointerException("Output stream is null");
        }

        final byte[] buf = new byte[2048];
        int len;
        while ((len = in.read(buf)) > 0) {
            out.write(buf, 0, len);
        }
    }
}

Related

  1. copyStream(InputStream in, OutputStream out)
  2. copyStream(InputStream in, OutputStream out)
  3. copyStream(InputStream in, OutputStream out)
  4. copyStream(InputStream in, OutputStream out)
  5. copyStream(InputStream in, OutputStream out)
  6. copyStream(InputStream in, OutputStream out)
  7. copyStream(InputStream in, OutputStream out)
  8. copyStream(InputStream in, OutputStream out)
  9. copyStream(InputStream in, OutputStream out)