Class CloseableResource<T>

  • Type Parameters:
    T - the type of the wrapped resource
    All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable
    Direct Known Subclasses:
    BlockLock, CloseableIterator, PooledResource

    public abstract class CloseableResource<T>
    extends java.lang.Object
    implements java.io.Closeable
    A CloseableResource<T> is a wrapper around a resource of type T which must do some sort of cleanup when it is no longer in use.
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      void close()  
      abstract void closeResource()
      Performs any cleanup operations necessary when the resource is no longer in use.
      T get()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • CloseableResource

        public CloseableResource​(T resource)
        Creates a CloseableResource wrapper around the given resource. This resource will be returned by the get() method.
        Parameters:
        resource - the resource to wrap
    • Method Detail

      • get

        public T get()
        Returns:
        the resource
      • close

        public void close()
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
      • closeResource

        public abstract void closeResource()
        Performs any cleanup operations necessary when the resource is no longer in use.