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

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

Description

copy Stream

License

Apache License

Declaration

public static void copyStream(InputStream is, OutputStream os) throws IOException 

Method Source Code


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

import java.io.*;

public class Main {
    private static final int DEFAULT_BUFFER_SIZE = 1024;

    public static void copyStream(InputStream is, OutputStream os) throws IOException {
        if (is == null) {
            throw new IllegalArgumentException("InputStream is null");
        }//from  ww w. jav a2 s  . com

        if (os == null) {
            throw new IllegalArgumentException("OutputStream is null");
        }

        byte[] b = new byte[DEFAULT_BUFFER_SIZE];
        int len = 0;

        try {
            while ((len = is.read(b, 0, DEFAULT_BUFFER_SIZE)) != -1) {
                os.write(b, 0, len);
            }
        } finally {
            is.close();
            os.flush();
        }
    }
}

Related

  1. copyStream(InputStream inStream, OutputStream outStream)
  2. copyStream(InputStream inStream, OutputStream outStream)
  3. copyStream(InputStream is, OutputStream os)
  4. copyStream(InputStream is, OutputStream os)
  5. copyStream(InputStream is, OutputStream os)
  6. copyStream(InputStream is, OutputStream os)
  7. copyStream(InputStream is, OutputStream os)
  8. copyStream(InputStream is, OutputStream os)
  9. copyStream(InputStream is, OutputStream os)