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.adaptris.core.util.JdbcUtil.java

public static void closeQuietly(AutoCloseable... closeables) {
    if (closeables != null) {
        for (AutoCloseable c : closeables) {
            try {
                if (c != null)
                    c.close();
            } catch (Exception e) {
            }//from  w w w  .j  av a  2s  . c  o  m
        }
    }
}

From source file:org.ireas.mediawiki.MediaWikiUtils.java

/**
 * Closes {@code closeable} (if not {@code null}) and ignores any exception
 * thrown closing the object./*from   w  w w.  j  av  a2 s  .  c o m*/
 *
 * @param closeable
 *            the object to close
 */
public static void close(@Nullable final AutoCloseable closeable) {
    if (closeable != null) {
        try {
            closeable.close();
        } catch (Exception exception) {
            ignoreException(exception);
        }
    }
}

From source file:org.ovirt.engine.extension.aaa.jdbc.core.datasource.Sql.java

public static void closeQuietly(AutoCloseable... closables) {
    for (AutoCloseable closable : closables) {
        if (closable != null) {
            try {
                closable.close();
            } catch (Exception e) {
                LOG.warn("Cannot close AutoCloseable {}, ignoring.", closable.getClass().getName());
                LOG.debug("Exception", e);
            }/*w  ww. j  a v a  2 s .co m*/
        }
    }
}

From source file:com.wavemaker.commons.util.IOUtils.java

public static void closeByLogging(AutoCloseable e) {
    if (e != null) {
        try {/*www  .j  a va  2 s  .  c  om*/
            e.close();
        } catch (Exception exc) {
            logger.warn("Failed to close the stream", exc);
        }
    }
}

From source file:com.wavemaker.commons.util.IOUtils.java

public static void closeSilently(AutoCloseable stream) {
    if (stream != null) {
        try {/*from  w  w  w  .ja v  a 2  s .c o m*/
            stream.close();
        } catch (Exception exc) {
        }
    }
}

From source file:example.tests.InitialLoadTest.java

private void closeSafe(AutoCloseable a) {
    try {// w w w. j a  v  a  2 s  .  c om
        a.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:io.fluo.metrics.config.Reporters.java

@Override
public void close() {
    for (AutoCloseable reporter : reporters) {
        try {/*w w w. j a  v  a2 s. c o  m*/
            reporter.close();
        } catch (Exception e) {
            log.warn("Failed to stop " + reporter.getClass().getName(), e);
        }
    }
}

From source file:org.sonar.api.utils.System2.java

/**
 * Closes the object and throws an {@link java.lang.IllegalStateException} on error.
 * @since 5.1//from   www. j a v  a 2  s .  c  o m
 */
public void close(AutoCloseable closeable) {
    try {
        closeable.close();
    } catch (Exception e) {
        throw new IllegalStateException("Fail to close " + closeable, e);
    }
}

From source file:com.example.android.directoryselection.DirectorySelectionFragment.java

public void closeQuietly(AutoCloseable closeable) {
    if (closeable != null) {
        try {/*from  www. ja v  a 2 s  . c  om*/
            closeable.close();
        } catch (RuntimeException rethrown) {
            throw rethrown;
        } catch (Exception ignored) {
        }
    }
}

From source file:org.apache.flink.tests.util.FlinkDistribution.java

@Override
public void afterTestSuccess() {
    try {/*  w ww.  j av  a  2 s. c o m*/
        stopFlinkCluster();
    } catch (IOException e) {
        LOG.error("Failure while shutting down Flink cluster.", e);
    }

    final Path originalConfig = conf.resolve(FLINK_CONF_YAML);
    final Path backupConfig = conf.resolve(FLINK_CONF_YAML_BACKUP);

    try {
        Files.move(backupConfig, originalConfig, StandardCopyOption.REPLACE_EXISTING);
    } catch (IOException e) {
        LOG.error("Failed to restore flink-conf.yaml", e);
    }

    for (AutoCloseable fileToDelete : filesToDelete) {
        try {
            fileToDelete.close();
        } catch (Exception e) {
            LOG.error("Failure while cleaning up file.", e);
        }
    }
}