Package org.bytemechanics.commons.lang
Class AutoCloseableResource
- java.lang.Object
-
- org.bytemechanics.commons.lang.AutoCloseableResource
-
- All Implemented Interfaces:
AutoCloseable
public class AutoCloseableResource extends Object implements AutoCloseable
This class intend to convert any resource that needs to be closed but does not implement AutoCloseable to a Closeable resource in order to be able to use into a Try-With-Resource structure- Since:
- 1.4.0
- Author:
- afarre
- See Also:
AutoCloseable
-
-
Constructor Summary
Constructors Constructor Description AutoCloseableResource(Runnable _try, Runnable _close)
Builds a Closeable resource with the given instance the _try Runnable will be executed during constructor and the _close one during close() methodAutoCloseableResource(Supplier<TYPE> _try, Consumer<TYPE> _close)
Builds a Closeable resource from it's supplier and consumer.
-
-
-
Constructor Detail
-
AutoCloseableResource
public AutoCloseableResource(Supplier<TYPE> _try, Consumer<TYPE> _close)
Builds a Closeable resource from it's supplier and consumer. Supplier will be executed during instantiation and consumer will be executed during close()- Type Parameters:
TYPE
- Type to convert to closeable resource- Parameters:
_try
- supplier to execute in this constructor_close
- consumer to be executed during close
-
AutoCloseableResource
public AutoCloseableResource(Runnable _try, Runnable _close)
Builds a Closeable resource with the given instance the _try Runnable will be executed during constructor and the _close one during close() method- Parameters:
_try
- Runnable to execute in this constructor_close
- Runnable to be executed during close
-
-
Method Detail
-
close
public void close() throws Exception
- Specified by:
close
in interfaceAutoCloseable
- Throws:
Exception
- See Also:
AutoCloseable.close()
-
-