Class Closer
java.lang.Object
org.apache.jackrabbit.oak.commons.pio.Closer
- All Implemented Interfaces:
Closeable,AutoCloseable
Convenience utility to close a list of
Closeables in reverse order,
suppressing all but the first exception to occur.
Inspired by and replacing Guava's Closer.
-
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes the set ofCloseables in reverse order.static Closercreate()Create instance of Closer.<C extends Closeable>
Cregister(C closeable) Add aCloseableto the list.Sets a flag indicating that this method was called, then rethrows the given exception (potentially wrapped intoErrororRuntimeException).
-
Method Details
-
create
Create instance of Closer. -
register
Add aCloseableto the list.- Parameters:
closeable-Closeableobject to be added- Returns:
- the closeable param
-
close
Closes the set ofCloseables in reverse order.Swallows all exceptions except the first that was thrown.
If
rethrow(java.lang.Throwable)was called before, even the first exception will be suppressed.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-
rethrow
Sets a flag indicating that this method was called, then rethrows the given exception (potentially wrapped intoErrororRuntimeException).close()will not throw when this method was called before.- Returns:
- never returns
- Throws:
IOException- wrapping the input, when needed
-