Java Stream Close close(Collection inCloseables)

Here you can find the source of close(Collection inCloseables)

Description

close

License

Open Source License

Declaration

public static void close(Collection<Closeable> inCloseables) 

Method Source Code

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

import java.io.Closeable;

import java.io.IOException;

import java.io.OutputStream;

import java.io.Writer;

import java.util.Collection;

public class Main {
    public static void close(Closeable inCloseable) {
        close(inCloseable, false);/*from   ww  w .  j  a v  a 2 s  .  com*/
    }

    public static void close(Closeable inCloseable, boolean inFlush) {

        if (inFlush) {
            flush(inCloseable);
        }

        try {

            inCloseable.close();

        } catch (final Exception e) {
        }

    }

    public static void close(Closeable... inCloseable) {

        if (inCloseable != null) {

            for (final Closeable closeable : inCloseable) {

                close(closeable);
            }
        }
    }

    public static void close(Collection<Closeable> inCloseables) {

        if (inCloseables != null) {

            for (final Closeable closeable : inCloseables) {

                close(closeable);
            }
        }
    }

    public static void flush(OutputStream inOutputStream) {

        try {

            inOutputStream.flush();

        } catch (final IOException e) {
            // swallow
        }
    }

    public static void flush(Writer inWriter) {

        try {

            inWriter.flush();

        } catch (final IOException e) {
            // swallow
        }
    }

    public static void flush(Object inOut) {

        if (inOut instanceof OutputStream) {

            flush((OutputStream) inOut);
        } else if (inOut instanceof Writer) {

            flush((Writer) inOut);
        }
    }
}

Related

  1. close(Closeable resource)
  2. close(Closeable resource)
  3. close(Closeable resource, File file)
  4. close(Closeable stream)
  5. close(Closeable... streams)
  6. close(DataOutputStream out)
  7. close(File file)
  8. close(FileReader fr)
  9. close(FileReader reader, BufferedReader br)