Java Stream Close close(final Logger logger, final Closeable... closeables)

Here you can find the source of close(final Logger logger, final Closeable... closeables)

Description

Close Closeable resource.

License

Open Source License

Parameter

Parameter Description
logger Logger instance, can be <code>null</code> if logging not required
closeables Closeable array

Declaration

public static void close(final Logger logger, final Closeable... closeables) 

Method Source Code


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

import java.io.Closeable;
import java.io.IOException;
import org.slf4j.Logger;

public class Main {
    /**/*w w w  .  j  av  a2  s .co m*/
     * Close {@link Closeable} resource.
     * 
     * @param closeables
     *            {@link Closeable} array
     */
    public static void close(final Closeable... closeables) {
        close(null, closeables);
    }

    /**
     * Close {@link Closeable} resource.
     * 
     * @param logger
     *            {@link Logger} instance, can be <code>null</code> if logging not required
     * @param closeables
     *            {@link Closeable} array
     */
    public static void close(final Logger logger, final Closeable... closeables) {
        if (closeables == null || closeables.length == 0)
            return;

        for (final Closeable c : closeables)
            if (c != null)
                try {
                    c.close();
                } catch (final IOException e) {
                    if (logger != null && logger.isDebugEnabled())
                        logger.debug("Closing[" + c + "] fail", e);
                }
    }
}

Related

  1. close(final Exception e, final Closeable... objects)
  2. close(final InputStream anInputStream)
  3. close(final InputStream is)
  4. close(final InputStream stream)
  5. close(final InputStream stream)
  6. close(final Object stream)
  7. close(final OutputStream dest)
  8. close(final Scanner scanner)
  9. close(Iterator iterator)