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

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

Description

copy Stream

License

Open Source License

Declaration

public static void copyStream(final InputStream is, final 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 {

    public static void copyStream(final InputStream is, final OutputStream os) throws IOException {
        byte[] buf = new byte[16 * 1024];
        while (true) {
            int len = is.read(buf);
            if (len <= 0) {
                break;
            }//from  w  ww. j  av  a 2s.  com
            os.write(buf, 0, len);
        }
    }

    public static void copyStream(final InputStream is, final OutputStream os, final boolean close)
            throws IOException {
        try {
            try {
                copyStream(is, os);
            } finally {
                if (close) {
                    os.close();
                }
            }
        } finally {
            if (close) {
                is.close();
            }
        }
    }
}

Related

  1. copyStream(final InputStream input, final OutputStream output, long count)
  2. copyStream(final InputStream inputStream, final OutputStream out)
  3. copyStream(final InputStream inputStream, final OutputStream outputStream)
  4. copyStream(final InputStream inputStream, final OutputStream outputStream)
  5. copyStream(final InputStream inputStream, final OutputStream outputStream)
  6. copyStream(final InputStream is, final OutputStream os)
  7. copyStream(final InputStream is, final OutputStream out, final Long amount, final int bufferSize)
  8. copyStream(final InputStream source, final OutputStream target)
  9. copyStream(final InputStream src, OutputStream dest)