Java InputStream to OutputStream copyStream(InputStream input, OutputStream output)

Here you can find the source of copyStream(InputStream input, OutputStream output)

Description

Copy the data from an InputStream to an OutputStream without closing the stream.

License

Apache License

Exception

Parameter Description
IOException an exception

Declaration

public static void copyStream(InputStream input, OutputStream output) 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 {
    public static final int DEFAULT_BUFFER_SIZE = 8192;

    /** Copy the data from an {@link InputStream} to an {@link OutputStream} without closing the stream.
     * @throws IOException *//* ww  w  .ja v  a 2  s.c o  m*/
    public static void copyStream(InputStream input, OutputStream output) throws IOException {
        copyStream(input, output, DEFAULT_BUFFER_SIZE);
    }

    /** Copy the data from an {@link InputStream} to an {@link OutputStream} without closing the stream.
     * @throws IOException */
    public static void copyStream(InputStream input, OutputStream output, int bufferSize) throws IOException {
        byte[] buffer = new byte[bufferSize];
        int bytesRead;
        while ((bytesRead = input.read(buffer)) != -1) {
            output.write(buffer, 0, bytesRead);
        }
    }
}

Related

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