List of usage examples for java.io Closeable close
public void close() throws IOException;
From source file:org.rhq.core.util.stream.StreamUtil.java
/** * Can be used to safely close a stream. No-op if the stream is null. * //from w w w .j a v a2s . c o m * @param stream the stream to close or null */ public static void safeClose(Closeable stream) { if (stream != null) { try { stream.close(); } catch (IOException e) { LOG.error("Failed to close a stream.", e); } } }
From source file:edu.umd.umiacs.clip.tools.io.AllFiles.java
protected static Runnable asUncheckedRunnable(Closeable c) { return () -> { try {//from w w w. j a v a 2 s . co m c.close(); } catch (IOException e) { throw new UncheckedIOException(e); } }; }
From source file:org.apache.spark.network.util.JavaUtils.java
/** Closes the given object, ignoring IOExceptions. */ public static void closeQuietly(Closeable closeable) { try {//ww w .j a v a 2 s . c om if (closeable != null) { closeable.close(); } } catch (IOException e) { logger.error("IOException should not have been thrown.", e); } }
From source file:parquet.compat.test.Utils.java
public static void closeQuietly(Closeable res) { try {// w w w .j a v a2s. c om if (res != null) { res.close(); } } catch (IOException ioe) { LOG.warn("Exception closing reader " + res + ": " + ioe.getMessage()); } }
From source file:com.buaa.cfs.utils.IOUtils.java
/** * Close the Closeable objects and <b>ignore</b> any {@link IOException} or null pointers. Must only be used for * cleanup in exception handlers.// ww w.j a v a 2s . c om * * @param log the log to record problems to at debug level. Can be null. * @param closeables the objects to close */ public static void cleanup(Log log, Closeable... closeables) { for (Closeable c : closeables) { if (c != null) { try { c.close(); } catch (IOException e) { if (log != null && log.isDebugEnabled()) { log.debug("Exception in closing " + c, e); } } } } }
From source file:org.xsystem.utils.Auxilary.java
public static Closeable close(Closeable closeable) { if (closeable != null) { try {//from www. j a v a2 s .c o m closeable.close(); } catch (IOException e) { e.printStackTrace(); } } ; return null; }
From source file:org.wikidata.wdtk.client.DumpProcessingOutputAction.java
/** * Closes a Closeable and swallows any exceptions that might occur in the * process.// w w w . j a va 2 s . c om * * @param closeable */ private static void close(Closeable closeable) { if (closeable != null) { try { closeable.close(); } catch (IOException ignored) { logger.error("Failed to close output stream: " + ignored.getMessage()); } } }
From source file:org.jboss.as.logging.LoggingResourceDefinition.java
private static void safeClose(final Closeable closeable) { if (closeable != null) try {/*www. j a v a 2 s . c o m*/ closeable.close(); } catch (Throwable t) { LoggingLogger.ROOT_LOGGER.failedToCloseResource(t, closeable); } }
From source file:org.waveprotocol.box.server.persistence.file.FileUtils.java
/** * Close the closeable and log, but ignore, any exception thrown. *//*from w ww . j a v a 2s. co m*/ public static void closeAndIgnoreException(Closeable closeable, File file, Log LOG) { if (closeable != null) { try { closeable.close(); } catch (IOException e) { // This should never happen in practice. But just in case... log it. LOG.warning("Failed to close file: " + file.getAbsolutePath(), e); } } }
From source file:org.apache.geode.internal.util.IOUtils.java
/** * Invokes the close method on any class instance implementing the Closeable interface, such as * InputStreams and OutputStreams. Note, this method silently ignores the possible IOException * resulting from the close invocation.//from w ww .j ava2s .co m * <p/> * * @param obj an Object implementing the Closeable interface who's close method will be invoked. */ public static void close(final Closeable obj) { if (obj != null) { try { obj.close(); } catch (IOException ignore) { } } }