Class TemporaryFileDirectory
java.lang.Object
velox.api.layer1.common.temporaryfiles.TemporaryFileDirectory
Manages a directory reserved for temporary resources. Required, because all temp resources need an associated lock.
Reasons:
- Temp directories are pruned at Bookmap startup and shutdown.
- There might be multiple instances of Bookmap running simultaneously over the same settings dir (dev environment only).
- On user machines, there might be background threads that still use the resources at the time of shutdown. Unexpected deletion of those resources can lead to permanent corruption.
- Lock ensures that only unused resources will be pruned.
Typical usage pattern:
TempPath tempPath = TemporaryFileDirectory.DEFAULT.newTempPath(...);
Path path = tempPath.get(); // or tempPath.createDirectory()
// use the path
tempPath.dispose();
TempPath can also be used with try-with-resources.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiongetRoot()newTempPath(String pathName) Creates a TempPath with given name.newTempPath(String prefix, String suffix) Creates a TempPath with its name generated using the given prefix and suffix.voidremoveUnlockedFiles(boolean gcHackForMemoryMappedFiles)
-
Field Details
-
DEFAULT
-
-
Constructor Details
-
TemporaryFileDirectory
-
-
Method Details
-
getRoot
-
removeUnlockedFiles
public void removeUnlockedFiles(boolean gcHackForMemoryMappedFiles) - Parameters:
gcHackForMemoryMappedFiles- When true, increases the chance of memory mapped files to be deleted.- See Also:
-
newTempPath
Creates a TempPath with its name generated using the given prefix and suffix. Uses standard Java temp file generation.- Throws:
IOException- See Also:
-
newTempPath
Creates a TempPath with given name. Where possible, versionnewTempPath(String, String)is preferred.- Throws:
IOException
-