Java InputStream to OutputStream copyStream(OutputStream outStream, InputStream inStream)

Here you can find the source of copyStream(OutputStream outStream, InputStream inStream)

Description

Copies specified input stream to specified output stream.

License

Apache License

Declaration

public static void copyStream(OutputStream outStream, InputStream inStream) throws IOException 

Method Source Code

//package com.java2s;
//License from project: Apache License 

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

public class Main {
    /** /*from   ww w. j a  v a 2s.  com*/
     * Copies specified input stream to specified output stream.
     */
    public static void copyStream(OutputStream outStream, InputStream inStream) throws IOException {
        try {
            byte[] bytes = new byte[1024];
            int count = inStream.read(bytes);
            while (count > 0) {
                outStream.write(bytes, 0, count);
                count = inStream.read(bytes);
            }
        } catch (IOException e) {
            throw e;
        } finally {
            inStream.close();
        }
    }
}

Related

  1. copyStream(int bufferSize, InputStream in, OutputStream out, boolean canStop)
  2. copyStream(java.io.InputStream in, java.io.OutputStream out)
  3. copyStream(java.io.InputStream inputStream, java.io.OutputStream outputStream)
  4. copyStream(java.io.InputStream src, java.io.OutputStream dest)
  5. copyStream(OutputStream out, InputStream in, int bufsz)
  6. copyStream(Reader input, Writer output)
  7. copyStreamAndClose(InputStream is, OutputStream os)
  8. copyStreamAndClose(InputStream is, OutputStream os)
  9. copyStreamBounded(InputStream in, OutputStream out, long length)