Java InputStream to OutputStream copyStream(final InputStream inputStream, final OutputStream outputStream)

Here you can find the source of copyStream(final InputStream inputStream, final OutputStream outputStream)

Description

copy Stream

License

LGPL

Declaration

public static int copyStream(final InputStream inputStream, final OutputStream outputStream)
            throws IOException 

Method Source Code

//package com.java2s;

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

import java.io.OutputStream;

public class Main {
    static final int BUFFER = 8 * 1024;

    public static int copyStream(final InputStream inputStream, final OutputStream outputStream)
            throws IOException {
        int result = 0;
        final byte[] buf = new byte[BUFFER];
        for (;;) {
            final int numRead = inputStream.read(buf);
            if (numRead == -1) {
                break;
            }/*from w  w  w .j  av a  2 s .com*/
            outputStream.write(buf, 0, numRead);
            result += numRead;
        }
        outputStream.flush();
        return result;
    }
}

Related

  1. copyStream(final InputStream in, final OutputStream out, int iMax)
  2. copyStream(final InputStream input, final OutputStream output, long count)
  3. copyStream(final InputStream inputStream, final OutputStream out)
  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 os)
  8. copyStream(final InputStream is, final OutputStream out, final Long amount, final int bufferSize)
  9. copyStream(final InputStream source, final OutputStream target)