Java Stream Close closeStream(final Object stream)

Here you can find the source of closeStream(final Object stream)

Description

Close an InputStream or OutputStream.

License

Open Source License

Parameter

Parameter Description
stream stream to close.

Declaration

public static void closeStream(final Object stream) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

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

public class Main {
    /**/*w  ww  .  j  av a2s.c o  m*/
     * Close an InputStream or OutputStream.
     *
     * @param stream
     *            stream to close.
     */
    public static void closeStream(final Object stream) {
        try {
            if (stream instanceof OutputStream) {
                OutputStream out = (OutputStream) stream;
                try {
                    out.flush();
                } finally {
                    out.close();
                }
            } else if (stream instanceof InputStream) {
                ((InputStream) stream).close();
            }
        } catch (Exception e) {
            // ignore
        }
    }
}

Related

  1. closeStream(FileInputStream in)
  2. closeStream(final Closeable stream)
  3. closeStream(final InputStream in)
  4. closeStream(final InputStream stream)
  5. closeStream(final java.io.Closeable stream)
  6. closeStream(InputStream in)
  7. closeStream(InputStream in)
  8. closeStream(InputStream inputStream)
  9. closeStream(InputStream ins)