javadoc.com.google.common.io.Closeables.html Maven / Gradle / Ivy
Closeables (Guava: Google Core Libraries for Java - release 05)
Overview
Package
Class
Use
Tree
Deprecated
Index
Help
PREV CLASS
NEXT CLASS
FRAMES
NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD
DETAIL: FIELD | CONSTR | METHOD
com.google.common.io
Class Closeables
java.lang.Object
com.google.common.io.Closeables
Utility methods for working with Closeable
objects.
- Since:
- 1
- Author:
- Michael Lancaster
Method Summary | |
---|---|
static void |
close(Closeable closeable,
boolean swallowIOException)
Closes a Closeable , with control over whether an
IOException may be thrown. |
static void |
closeQuietly(Closeable closeable)
Equivalent to calling close(closeable, true) , but with no
IOException in the signature. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
close
public static void close(@Nullable Closeable closeable, boolean swallowIOException) throws IOException
- Closes a
Closeable
, with control over whether anIOException
may be thrown. This is primarily useful in a finally block, where a thrown exception needs to be logged but not propagated (otherwise the original exception will be lost).If
swallowIOException
is true then we never throwIOException
but merely log it.Example:
public void useStreamNicely() throws IOException { SomeStream stream = new SomeStream("foo"); boolean threw = true; try { // Some code which does something with the Stream. May throw a // Throwable. threw = false; // No throwable thrown. } finally { // Close the stream. // If an exception occurs, only rethrow it if (threw==false). Closeables.close(stream, threw); }
- Parameters:
closeable
- theCloseable
object to be closed, or null, in which case this method does nothingswallowIOException
- if true, don't propagate IO exceptions thrown by theclose
methods- Throws:
IOException
- ifswallowIOException
is false andclose
throws anIOException
.
closeQuietly
public static void closeQuietly(@Nullable Closeable closeable)
- Equivalent to calling
close(closeable, true)
, but with no IOException in the signature.- Parameters:
closeable
- theCloseable
object to be closed, or null, in which case this method does nothing
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |