Class FileSystemState

java.lang.Object
com.google.common.jimfs.FileSystemState
All Implemented Interfaces:
Closeable, AutoCloseable

final class FileSystemState extends Object implements Closeable
Object that manages the open/closed state of a file system, ensuring that all open resources are closed when the file system is closed and that file system methods throw an exception when the file system has been closed.
  • Field Details

    • resources

      private final Set<Closeable> resources
    • fileTimeSource

      private final FileTimeSource fileTimeSource
    • onClose

      private final Runnable onClose
    • open

      private final AtomicBoolean open
    • registering

      private final AtomicInteger registering
      Count of resources currently in the process of being registered.
  • Constructor Details

  • Method Details

    • isOpen

      public boolean isOpen()
      Returns whether or not the file system is open.
    • checkOpen

      public void checkOpen()
      Checks that the file system is open, throwing ClosedFileSystemException if it is not.
    • register

      @CanIgnoreReturnValue public <C extends Closeable> C register(C resource)
      Registers the given resource to be closed when the file system is closed. Should be called when the resource is opened.
    • unregister

      public void unregister(Closeable resource)
      Unregisters the given resource. Should be called when the resource is closed.
    • now

      public FileTime now()
      Returns the current FileTime.
    • close

      public void close() throws IOException
      Closes the file system, runs the onClose callback and closes all registered resources.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Throws:
      IOException