Java InputStream to OutputStream copyStream(InputStream is, OutputStream os)

Here you can find the source of copyStream(InputStream is, OutputStream os)

Description

Copy data from an InputStream to an OutputStream.

License

Open Source License

Parameter

Parameter Description
is a parameter
os a parameter

Exception

Parameter Description
IOException an exception

Declaration

static public void copyStream(InputStream is, OutputStream os) 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 {
    /**/*from  w  w w  .j  a  v  a2s .  co m*/
     * Copy data from an InputStream to an OutputStream.
     * 
     * @param is
     * @param os
     * @throws IOException
     */
    static public void copyStream(InputStream is, OutputStream os) throws IOException {
        copyStream(is, os, false);
    }

    /**
     * Copy data from an InputStream to an OutputStream. Close the OutputStream
     * after copying if closeOs is set to {@code true}.
     * 
     * @param is
     * @param os
     * @param closeOs
     * @throws IOException
     */
    static public void copyStream(InputStream is, OutputStream os, boolean closeOs) throws IOException {
        byte[] buf = new byte[8192];
        int n;
        while ((n = is.read(buf, 0, 8192)) != -1) {
            os.write(buf, 0, n);
        }
        os.flush();
        if (closeOs)
            os.close();
    }
}

Related

  1. copyStream(InputStream is, OutputStream os)
  2. copyStream(InputStream is, OutputStream os)
  3. copyStream(InputStream is, OutputStream os)
  4. CopyStream(InputStream is, OutputStream os)
  5. copyStream(InputStream is, OutputStream os)
  6. copyStream(InputStream is, OutputStream os)
  7. copyStream(InputStream is, OutputStream os)
  8. copyStream(InputStream is, OutputStream os)
  9. copyStream(InputStream is, OutputStream os)