public final class AutoCloser extends Object implements AutoCloseable
Closer, that supports AutoCloseables.
See https://github.com/google/guava/issues/1020
Also, this class contains static utility methods for closing multiple AutoCloseables at once.| Modifier and Type | Method and Description |
|---|---|
void |
close()
Closes all
AutoCloseable instances that have been added to this AutoCloser. |
static <T extends Throwable> |
close(AutoCloseable... theCloseables) |
static <E extends Exception> |
close(Iterable<? extends AutoCloseable> theCloseables) |
static void |
closeSuppressedBy(Exception theE,
AutoCloseable... theCloseables) |
static AutoCloser |
create()
Creates a new
AutoCloser. |
<C extends AutoCloseable> |
register(C closeable)
|
RuntimeException |
rethrow(Throwable e)
Stores the given throwable and rethrows it.
|
public static <E extends Exception> void close(Iterable<? extends AutoCloseable> theCloseables) throws E extends Exception
E extends Exceptionpublic static <T extends Throwable> void close(AutoCloseable... theCloseables) throws T extends Throwable
T extends Throwablepublic static void closeSuppressedBy(Exception theE, AutoCloseable... theCloseables)
public static AutoCloser create()
AutoCloser.public <C extends AutoCloseable> C register(@Nullable C closeable)
closeablepublic RuntimeException rethrow(Throwable e) throws Exception
This method always throws, and as such should be called as throw closer.rethrow(e);
to ensure the compiler knows that it will throw.
Exception - when the given throwable is an Exceptionpublic void close()
throws Exception
AutoCloseable instances that have been added to this AutoCloser. If an exception was
thrown in the try block and passed to one of the exceptionThrown methods, any exceptions thrown when
attempting to close a closeable will be suppressed. Otherwise, the first exception to be thrown from
an attempt to close a closeable will be thrown and any additional exceptions that are thrown after that will
be suppressed.close in interface AutoCloseableExceptionCopyright © 2010-2016 Stardog Union. All Rights Reserved.