Class SuppressingCloser
- java.lang.Object
-
- org.hibernate.search.util.common.impl.AbstractCloser<SuppressingCloser,Exception>
-
- org.hibernate.search.util.common.impl.SuppressingCloser
-
public final class SuppressingCloser extends AbstractCloser<SuppressingCloser,Exception>
A helper for closing multiple resources and re-throwing a provided exception,suppressingany exceptions caught while closing.This class is not thread safe.
This helper is mainly useful when implementing a
catchblock 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
AbstractClosersuperclass for a list of methods allowing to close objects while catching exceptions.
-
-
Constructor Summary
Constructors Constructor Description SuppressingCloser(Throwable mainThrowable)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description SuppressingCloserpush(AutoCloseable closeable)Close the givencloseableimmediately, swallowing any throwable in order toadd it as suppressedto the main throwable.<T> SuppressingCloserpush(T objectToExtractFrom, Function<T,? extends AutoCloseable> extract)Close thecloseableextracted fromobjectToExtractFromimmediately, swallowing any throwable in order toadd it as suppressedto the main throwable.SuppressingCloserpushAll(AutoCloseable... closeables)Close the givencloseablesimmediately, swallowing any throwable in order toadd it as suppressedto the main throwable.SuppressingCloserpushAll(Iterable<? extends AutoCloseable> closeables)Close the givencloseablesimmediately, swallowing any throwable in order toadd it as suppressedto the main throwable.<U> SuppressingCloserpushAll(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 Detail
-
SuppressingCloser
public SuppressingCloser(Throwable mainThrowable)
-
-
Method Detail
-
push
public SuppressingCloser push(AutoCloseable closeable)
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
public SuppressingCloser pushAll(AutoCloseable... closeables)
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
public SuppressingCloser pushAll(Iterable<? extends AutoCloseable> closeables)
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.
-
-