Class SuppressingCloser
suppressing any exceptions caught while closing.
This class is not thread safe.
This helper is mainly useful when implementing a catch block where resources must be closed,
to make sure that all resources are at least given the chance to close, even if closing one of them fails,
and that you can still re-throw the originally caught exception.
See the AbstractCloser superclass for a list of methods
allowing to close objects while catching exceptions.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionpush(AutoCloseable closeable) Close the givencloseableimmediately, swallowing any throwable in order toadd it as suppressedto the main throwable.push(T objectToExtractFrom, Function<T, ? extends AutoCloseable> extract) Close thecloseableextracted fromobjectToExtractFromimmediately, swallowing any throwable in order toadd it as suppressedto the main throwable.pushAll(AutoCloseable... closeables) Close the givencloseablesimmediately, swallowing any throwable in order toadd it as suppressedto the main throwable.pushAll(Iterable<? extends AutoCloseable> closeables) Close the givencloseablesimmediately, swallowing any throwable in order toadd it as suppressedto the main throwable.pushAll(Iterable<? extends U> objectsToExtractFrom, Function<U, AutoCloseable> extract) Close theAutoCloseableelements extracted from elements ofobjectToExtractFromimmediately, swallowing any throwable in order toadd it as suppressedto the main throwable.
-
Constructor Details
-
SuppressingCloser
-
-
Method Details
-
push
Close the givencloseableimmediately, swallowing any throwable in order toadd it as suppressedto the main throwable.See also
AbstractCloser.push(ClosingOperator, Object)for when the object to close does not implementAutoCloseable.- Parameters:
closeable- AnAutoCloseableto close.- Returns:
this, for method chaining.
-
push
public <T> SuppressingCloser push(T objectToExtractFrom, Function<T, ? extends AutoCloseable> extract) Close thecloseableextracted fromobjectToExtractFromimmediately, swallowing any throwable in order toadd it as suppressedto the main throwable.See also
AbstractCloser.push(ClosingOperator, Object)for when the object to close does not implementAutoCloseable.- Parameters:
objectToExtractFrom- An object from which to extract the object to close.extract- A function to extract an object to close fromobjectToExtractFrom. Accepts lambdas such asMyType::get.- Returns:
this, for method chaining.
-
pushAll
Close the givencloseablesimmediately, swallowing any throwable in order toadd it as suppressedto the main throwable.See also
AbstractCloser.pushAll(ClosingOperator, Object[])for when the objects to close do not implementAutoCloseable.- Parameters:
closeables- An array ofAutoCloseables to close.- Returns:
this, for method chaining.
-
pushAll
Close the givencloseablesimmediately, swallowing any throwable in order toadd it as suppressedto the main throwable.See also
AbstractCloser.pushAll(ClosingOperator, Iterable)for when the objects to close do not implementAutoCloseable.- Parameters:
closeables- An iterable ofAutoCloseables to close.- Returns:
this, for method chaining.
-
pushAll
public <U> SuppressingCloser pushAll(Iterable<? extends U> objectsToExtractFrom, Function<U, AutoCloseable> extract) Close theAutoCloseableelements extracted from elements ofobjectToExtractFromimmediately, swallowing any throwable in order toadd it as suppressedto the main throwable.See also
AbstractCloser.pushAll(ClosingOperator, Iterable, Function)for when the objects to close do not implementAutoCloseable.- Parameters:
objectsToExtractFrom- An iterable of objects from which to extract the objects to close.extract- A function to extract an object to close from the elements ofobjectsToExtractFrom. Accepts lambdas such asMyType::get.- Returns:
this, for method chaining.
-