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

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

Description

copy Stream

License

Open Source License

Declaration

public static void copyStream(InputStream input, OutputStream output, int bufferSize) throws Exception 

Method Source Code


//package com.java2s;
import java.io.InputStream;
import java.io.OutputStream;

public class Main {
    public static void copyStream(InputStream input, OutputStream output, int bufferSize) throws Exception {
        try {/*from ww w.j a va 2  s .c  o  m*/
            byte[] buf = new byte[bufferSize];
            int len;
            while ((len = input.read(buf)) > 0) {
                output.write(buf, 0, len);
            }
        } finally {
            if (input != null) {
                input.close();
            }
            if (output != null) {
                output.flush();
                output.close();
            }
        }
    }
}

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, boolean closeStreams)
  5. copyStream(InputStream input, OutputStream output, boolean closeStreams)
  6. copyStream(InputStream input, OutputStream output, int length)
  7. copyStream(InputStream inputStream, OutputStream outputStream)
  8. copyStream(InputStream inputStream, OutputStream outputStream)
  9. copyStream(InputStream inStream, OutputStream outStream)