Interface CompositeAutoClosable
-
- All Superinterfaces:
AutoCloseable
public interface CompositeAutoClosable extends AutoCloseable
Represents anAutoCloseablemade up of several otherAutoCloseables.The
close()method closes in LIFO (Last-In-First-Out) order.CompositeAutoClosables can be reused. The instance is effectively cleared on each invocation ofclose().
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description CompositeAutoClosablebind(AutoCloseable autoCloseable)Binds anAutoCloseablewith this composite closable.default CompositeAutoClosablebindAll(AutoCloseable... autoCloseables)Binds all givenAutoCloseablewith this composite closable.default CompositeAutoClosablebindAll(Iterable<? extends AutoCloseable> autoCloseables)Binds all givenAutoCloseablewith this composite closable.voidclose()Closes this composite resource.default voidcloseAndReportExceptions()Closes this composite resource, but simply prints any resultant exceptions instead of rethrowing them.default voidcloseSilently()Closes this composite resource, but doesn't rethrow or print any exceptions.static CompositeAutoClosablecreate()Creates a new standaloneCompositeAutoClosable.
-
-
-
Method Detail
-
create
static CompositeAutoClosable create()
Creates a new standaloneCompositeAutoClosable.- Returns:
- a new
CompositeAutoClosable.
-
bind
CompositeAutoClosable bind(AutoCloseable autoCloseable)
Binds anAutoCloseablewith this composite closable.Note that implementations do not keep track of duplicate contains closables. If a single
AutoCloseableis added twice, it will beclosedtwice.- Parameters:
autoCloseable- the closable to bind- Returns:
- this (for chaining)
- Throws:
NullPointerException- if the closable is null
-
bindAll
default CompositeAutoClosable bindAll(AutoCloseable... autoCloseables)
Binds all givenAutoCloseablewith this composite closable.Note that implementations do not keep track of duplicate contains closables. If a single
AutoCloseableis added twice, it will beclosedtwice.Ignores null values.
- Parameters:
autoCloseables- the closables to bind- Returns:
- this (for chaining)
-
bindAll
default CompositeAutoClosable bindAll(Iterable<? extends AutoCloseable> autoCloseables)
Binds all givenAutoCloseablewith this composite closable.Note that implementations do not keep track of duplicate contains closables. If a single
AutoCloseableis added twice, it will beclosedtwice.Ignores null values.
- Parameters:
autoCloseables- the closables to bind- Returns:
- this (for chaining)
-
close
void close() throws CompositeClosingExceptionCloses this composite resource.- Specified by:
closein interfaceAutoCloseable- Throws:
CompositeClosingException- if any of the sub instances throw an exception whilst closing
-
closeSilently
default void closeSilently()
Closes this composite resource, but doesn't rethrow or print any exceptions.- See Also:
close()
-
closeAndReportExceptions
default void closeAndReportExceptions()
Closes this composite resource, but simply prints any resultant exceptions instead of rethrowing them.
-
-