Java Stream Close closeAllStreamsQuietly(final Closeable... closeables)

Here you can find the source of closeAllStreamsQuietly(final Closeable... closeables)

Description

Closes a list of Closeable objects quietly.
The specified list may contain objects with null null values.

License

Open Source License

Parameter

Parameter Description
closeables - The list of <tt>Closeable</tt> object to close.

Declaration

public static void closeAllStreamsQuietly(final Closeable... closeables) 

Method Source Code


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

import java.io.Closeable;

import java.io.IOException;

public class Main {
    /**//ww w . j a va  2  s .  co m
     * Closes a list of <tt>Closeable</tt> objects quietly.<br>
     * The specified list may contain objects with null <tt>null</tt> values.
     * 
     * @param closeables - The list of <tt>Closeable</tt> object to close.
     * @see #closeStreamQuietly(Closeable)
     */
    public static void closeAllStreamsQuietly(final Closeable... closeables) {
        for (Closeable aCloseable : closeables) {
            closeStreamQuietly(aCloseable);
        }
    }

    /**
     * Close quietly an object which implements the {@link Closeable} interface
     * such as <tt>InputStream</tt>, <tt>OutputStream</tt>, <tt>Reader</tt> ...
     * 
     * @param closeable - The stream to close, if <tt>null</tt> nothing is done.
     * @see #closeAllStreamsQuietly(Closeable...)
     */
    public static void closeStreamQuietly(final Closeable closeable) {
        try {
            if (closeable != null)
                closeable.close();
        } catch (IOException ioe) {
            // Do nothing.
        }
    }
}

Related

  1. closeAll()
  2. closeAll(Collection closeables)
  3. closeAll(Exception firstEx, Closeable... objects)
  4. closeAll(Iterable closeables)
  5. closeAll(T... io)
  6. closeAndRethrow(final Exception e, final Closeable... channels)
  7. closeBufferedFile(BufferedReader reader)
  8. closeBufferedReader(BufferedReader bufferedReader)
  9. closeCloseableIfNotNull(Closeable fileWriter)