| java.lang.Object | |
| ↳ | com.google.gdata.util.common.io.Closeables |
Utility methods for working with Closeable objects.
| Fields | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| logger | |||||||||||
| Public Methods | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
Closes a Closeable, with control over whether an
IOException may be thrown. | |||||||||||
Equivalent to calling
close(closeable, true), but with no
IOException in the signature. | |||||||||||
|
[Expand]
Inherited Methods | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
| |||||||||||
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 {
// 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);
}
| 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.
|
|---|
Equivalent to calling close(closeable, true), but with no
IOException in the signature.
| closeable | The Closeable object to be closed, or null, in
which case this method does nothing
|
|---|