Example usage for java.lang AutoCloseable close

List of usage examples for java.lang AutoCloseable close

Introduction

In this page you can find the example usage for java.lang AutoCloseable close.

Prototype

void close() throws Exception;

Source Link

Document

Closes this resource, relinquishing any underlying resources.

Usage

From source file:com.griefcraft.util.Closer.java

/**
 * Quietly closes a closeable object, ignoring all exceptions.
 * /*  w w w.  j av a2s.c  om*/
 * @param closeable Object to close
 */
public static void closeQuietly(AutoCloseable closeable) {
    try {
        if (closeable != null)
            closeable.close();
    } catch (Throwable ex) {
    }
}

From source file:com.anthonymandra.support.v4.provider.DocumentsContractApi21.java

private static void closeQuietly(AutoCloseable closeable) {
    if (closeable != null) {
        try {/*from ww w  . java  2s.co  m*/
            closeable.close();
        } catch (RuntimeException rethrown) {
            throw rethrown;
        } catch (Exception ignored) {
        }
    }
}

From source file:com.dsclab.loader.export.DBClient.java

private static void safeClose(AutoCloseable close) throws Exception {
    if (close != null) {
        close.close();
    }//  w ww.j  av a2  s .  co m
}

From source file:io.fluo.core.metrics.ReporterUtil.java

public static AutoCloseable setupReporters(final Environment env, final String domain) {
    ServiceLoader<ReporterStarter> serviceLoader = ServiceLoader.load(ReporterStarter.class);

    final List<AutoCloseable> allReporters = new ArrayList<>();

    for (ReporterStarter rs : serviceLoader) {
        List<AutoCloseable> reporters = rs.start(new Params() {

            @Override/*from  w ww .j av a  2 s. co m*/
            public Configuration getConfiguration() {
                return env.getConfiguration();
            }

            @Override
            public MetricRegistry getMetricRegistry() {
                return env.getSharedResources().getMetricRegistry();
            }

            @Override
            public String getDomain() {
                return domain;
            }
        });

        allReporters.addAll(reporters);
    }

    if (allReporters.size() == 0) {
        JmxReporter jmxReporter = JmxReporter.forRegistry(env.getSharedResources().getMetricRegistry())
                .inDomain(domain).build();
        jmxReporter.start();
        allReporters.add(jmxReporter);
    }

    return new AutoCloseable() {

        @Override
        public void close() {
            for (AutoCloseable closeable : allReporters) {
                try {
                    closeable.close();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    };
}

From source file:org.openhab.binding.neeo.internal.NeeoUtil.java

/**
 * Utility function to close a {@link AutoCloseable} and log any exception thrown.
 *
 * @param closeable a possibly null {@link AutoCloseable}. If null, no action is done.
 *//*from  w  ww .j  ava  2 s.c om*/
public static void close(@Nullable AutoCloseable closeable) {
    if (closeable != null) {
        try {
            closeable.close();
        } catch (Exception e) {
            LoggerFactory.getLogger(NeeoUtil.class).debug("Exception closing: {}", e.getMessage(), e);
        }
    }
}

From source file:org.apache.kylin.common.persistence.JDBCConnectionManager.java

public static void closeQuietly(AutoCloseable obj) {
    if (obj != null) {
        try {/*from   w ww  .  ja v  a  2s .c  o m*/
            obj.close();
        } catch (Exception e) {
            logger.warn("Error closing " + obj, e);
        }
    }
}

From source file:com.javacreed.secureproperties.utils.DbHelper.java

/**
 *
 * @param closeable//ww w.j  a  va 2s  .  c  o  m
 */
public static void closeQuietly(final AutoCloseable closeable) {
    if (closeable != null) {
        try {
            closeable.close();
        } catch (final Exception e) {
        }
    }
}

From source file:com.anthonymandra.support.v4.provider.DocumentsContractApi19.java

public static void closeQuietly(AutoCloseable closeable) {
    if (closeable != null) {
        try {// w ww.  j  av a  2 s.c  om
            closeable.close();
        } catch (RuntimeException rethrown) {
            throw rethrown;
        } catch (Exception ignored) {
        }
    }
}

From source file:com.qwazr.utils.IOUtils.java

public static final void close(final AutoCloseable autoCloseable) {
    if (autoCloseable == null)
        return;//from  w  ww  .j  a  v  a  2s  .com
    try {
        autoCloseable.close();
    } catch (Exception e) {
        if (logger.isWarnEnabled())
            logger.warn("Close failure on " + autoCloseable, e);
    }
}

From source file:com.huawei.streaming.util.StreamingUtils.java

/**
 * /*  w ww.  j  a  v a2 s. c  o  m*/
 * @param statements ?
 */
public static void close(AutoCloseable... statements) {
    for (AutoCloseable sts : statements) {
        if (sts == null) {
            continue;
        }

        try {
            sts.close();
        } catch (Exception e) {
            LOG.warn("Failed to close statement.", e);
        }
    }
}