docs/javadoc/reference/com/facebook/common/internal/Closeables.html
|
|
ImmutableMap<K, V>
ImmutableSet<E>
Summary: Methods | Inherited Methods | [Expand All]
public final class
extends Object
| java.lang.Object | | ↳ | com.facebook.common.internal.Closeables |
Utility methods for working with Closeable objects.
| Public Methods |
|---|
| static void |
Closes a Closeable, with control over whether an IOException may be thrown. |
| static void |
Closes the given InputStream, logging any IOException that's thrown rather than propagating it. |
| static void |
Closes the given Reader, logging any IOException that's thrown rather than propagating it. |
| [Expand] Inherited Methods | | --- | | From class java.lang.Object
| Object | clone() | | boolean | equals(Object arg0) | | void | finalize() | | final Class<?> | getClass() | | int | hashCode() | | final void | notify() | | final void | notifyAll() | | String | toString() | | final void | wait(long arg0, int arg1) | | final void | wait(long arg0) | | final void | wait() |
|
Closes a Closeable, with control over whether an IOException 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 throw IOException but merely log it.
Example:
public void useStreamNicely() throws IOException {
SomeStream stream = new SomeStream("foo");
boolean threw = true;
try {
// ... code which does something with the stream ...
threw = false;finally {
// If an exception occurs, rethrow it only if threw==false:
Closeables.close(stream, threw);
}
}
}
| closeable | the Closeable object to be closed, or null, in which case this method does nothing |
| swallowIOException | if true, don't propagate IO exceptions thrown by the close methods |
| IOException | if swallowIOException is false and close throws an IOException. |
Closes the given InputStream, logging any IOException that's thrown rather than propagating it.
While it's not safe in the general case to ignore exceptions that are thrown when closing an I/O resource, it should generally be safe in the case of a resource that's being used only for reading, such as an InputStream. Unlike with writable resources, there's no chance that a failure that occurs when closing the stream indicates a meaningful problem such as a failure to flush all bytes to the underlying resource.
| inputStream | the input stream to be closed, or null in which case this method does nothing |
Closes the given Reader, logging any IOException that's thrown rather than propagating it.
While it's not safe in the general case to ignore exceptions that are thrown when closing an I/O resource, it should generally be safe in the case of a resource that's being used only for reading, such as a Reader. Unlike with writable resources, there's no chance that a failure that occurs when closing the reader indicates a meaningful problem such as a failure to flush all bytes to the underlying resource.
| reader | the reader to be closed, or null in which case this method does nothing |
+Generated by Doclava. +