Class AutoCloser<T,E extends Exception>
- java.lang.Object
-
- gov.nist.secauto.metaschema.core.util.AutoCloser<T,E>
-
- Type Parameters:
T
- the resource typeE
- the exception type that may be thrown if an error occurs when closing the resource
- All Implemented Interfaces:
AutoCloseable
public class AutoCloser<T,E extends Exception> extends Object implements AutoCloseable
Wraps a resource to make itAutoCloseable
.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
AutoCloser.Closer<T,E extends Exception>
-
Constructor Summary
Constructors Constructor Description AutoCloser(T resource, AutoCloser.Closer<T,E> lambda)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static <T,E extends Exception>
AutoCloser<T,E>autoClose(T resource, AutoCloser.Closer<T,E> lambda)
void
close()
T
getResource()
Get the wrapped resource.
-
-
-
Constructor Detail
-
AutoCloser
public AutoCloser(@NonNull T resource, @NonNull AutoCloser.Closer<T,E> lambda)
- Parameters:
resource
- the object to adaptlambda
- the lambda to use as a callback on close
-
-
Method Detail
-
autoClose
@NonNull public static <T,E extends Exception> AutoCloser<T,E> autoClose(@NonNull T resource, @NonNull AutoCloser.Closer<T,E> lambda)
- Type Parameters:
T
- the resource's typeE
- the exception type that can be thrown when closing- Parameters:
resource
- the object to adaptlambda
- the lambda to use as a callback on close- Returns:
- the resource wrapped in an
AutoCloseable
-
getResource
@NonNull public T getResource()
Get the wrapped resource.- Returns:
- the resource object
-
-