Class 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 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