Package com.google.common.jimfs
Class FileSystemState
java.lang.Object
com.google.common.jimfs.FileSystemState
- All Implemented Interfaces:
Closeable
,AutoCloseable
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 Summary
FieldsModifier and TypeFieldDescriptionprivate final FileTimeSource
private final Runnable
private final AtomicBoolean
private final AtomicInteger
Count of resources currently in the process of being registered. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
Checks that the file system is open, throwingClosedFileSystemException
if it is not.void
close()
Closes the file system, runs theonClose
callback and closes all registered resources.boolean
isOpen()
Returns whether or not the file system is open.now()
Returns the currentFileTime
.<C extends Closeable>
Cregister
(C resource) Registers the given resource to be closed when the file system is closed.void
unregister
(Closeable resource) Unregisters the given resource.
-
Field Details
-
resources
-
fileTimeSource
-
onClose
-
open
-
registering
Count of resources currently in the process of being registered.
-
-
Constructor Details
-
FileSystemState
FileSystemState(FileTimeSource fileTimeSource, Runnable onClose)
-
-
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, throwingClosedFileSystemException
if it is not. -
register
Registers the given resource to be closed when the file system is closed. Should be called when the resource is opened. -
unregister
Unregisters the given resource. Should be called when the resource is closed. -
now
Returns the currentFileTime
. -
close
Closes the file system, runs theonClose
callback and closes all registered resources.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
-