Package no.digipost.util
Class ThrowingAutoClosed<T,X extends Exception>
- java.lang.Object
-
- no.digipost.util.ThrowingAutoClosed<T,X>
-
- Type Parameters:
T- The type of the arbitrary object which will have an operation invoked on exiting from a try-with-resources block.X- The type of exception which may be throwed by thecloseOperation
- All Implemented Interfaces:
AutoCloseable
public final class ThrowingAutoClosed<T,X extends Exception> extends Object implements AutoCloseable
An adapter to enable any arbitrary object to be managed by the try-with-resources facility of Java >= 7, i.e. it will have a closing operation invoked when exiting thetry-block.
-
-
Constructor Summary
Constructors Constructor Description ThrowingAutoClosed(T managedObject, ThrowingConsumer<? super T,X> closeOperation)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Tobject()-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.lang.AutoCloseable
close
-
-
-
-
Constructor Detail
-
ThrowingAutoClosed
public ThrowingAutoClosed(T managedObject, ThrowingConsumer<? super T,X> closeOperation)
-
-
Method Detail
-
object
public T object()
- Returns:
- the object managed by try-with-resources.
-
close
public void close() throws X extends Exception- Throws:
X extends Exception- See Also:
AutoCloseable.close()
-
-