Class FilePathHelper
java.lang.Object
net.simplace.core.service.FilePathHelper
Singleton manager for temporary and cache directories.
Provides a session temp directory (unique while the software is running), a cache directory (shared by all sessions)
and random temp directories (unique per call). All of them are located below the temp root directory, which is read
from the system property SETTINGS.USER_TMP or set with setTempDirRoot(String).
- Author:
- Andreas Enders
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringSystem property that overrides the log directory (also used bylog4j2.xml). -
Method Summary
Modifier and TypeMethodDescriptionReturns the cache directory shared by all sessions.floatgetCacheVersion(String aSystemID, String aFileName, String aTargetDir) Reads the version of a cached file from the file<name>.versionin the target directory.static FilePathHelperReturns the singleton instance of FilePathHelper.static FileReturns the directory of the log files.static FilegetRandomFile(String aFileName) Returns a file with the given name in the session temp directory.Creates a new, uniquely named temp directory below the temp root directory.static FilegetResourcePath(File aFile) Looks up a file as resource on the class path of the context class loader.Returns the temp directory of this session.Returns the temp root directory shared by all sessions.getTempFile(String aFileName) Creates a new, empty file with a unique name in the session temp directory.booleanDeletes all files and directories in the temp root directory that have not been modified for about 11 hours (40,000 seconds).booleanDeletes the session temp directory with its content.voidsetNewCacheVersion(String aSystemID, String aFileName, String aTargetDir, float aVersion) Stores the version of a cached file in a file<name>.versionin the target directory.setTempDirRoot(String aFilePath) Sets the temp root directory, also in the system propertySETTINGS.USER_TMP, and creates it if it does not exist.
-
Field Details
-
LOG_DIR_PROPERTY
System property that overrides the log directory (also used bylog4j2.xml).- See Also:
-
-
Method Details
-
getInstance
Returns the singleton instance of FilePathHelper.- Returns:
- the singleton instance of FilePathHelper
-
getTempDirRoot
Returns the temp root directory shared by all sessions. The path is read from the system propertySETTINGS.USER_TMPif available, otherwise the last value set withsetTempDirRoot(String)is used. The directory is created if it does not exist.- Returns:
- path of the temp root directory, with forward slashes
-
setTempDirRoot
-
getTempDir
Returns the temp directory of this session. It is created below the temp root directory on first call and reused afterwards.- Returns:
- path of the session temp directory, with forward slashes
-
getRandomTempDir
Creates a new, uniquely named temp directory below the temp root directory. Each call returns a different directory.- Returns:
- path of the new directory, with forward slashes
-
getCacheDir
Returns the cache directory shared by all sessions. The path is read from the system propertySETTINGS.USER_CACHEif available, otherwise<temp root>/CACHEis used. The directory is created if it does not exist.- Returns:
- path of the cache directory, with forward slashes
-
setNewCacheVersion
public void setNewCacheVersion(String aSystemID, String aFileName, String aTargetDir, float aVersion) Stores the version of a cached file in a file<name>.versionin the target directory. Errors are logged, not thrown.- Parameters:
aSystemID- not usedaFileName- name or path of the cached file; only the file name is usedaTargetDir- directory in which the version file is writtenaVersion- version to store- See Also:
-
getCacheVersion
Reads the version of a cached file from the file<name>.versionin the target directory.- Parameters:
aSystemID- not usedaFileName- name or path of the cached file; only the file name is usedaTargetDir- directory containing the version file- Returns:
- the stored version, or 0 if there is no version file or it cannot be read
- See Also:
-
getRandomFile
-
getTempFile
Creates a new, empty file with a unique name in the session temp directory.- Parameters:
aFileName- template for the file name; the extension from the last.(e.g..xml) is used as suffix, the rest as prefix (extended to the minimum length of 3 characters)- Returns:
- the created file
- Throws:
IOException- if the file cannot be created
-
removeTempDir
public boolean removeTempDir()Deletes the session temp directory with its content.- Returns:
trueif the directory was deleted
-
removeAllClientTempDirs
public boolean removeAllClientTempDirs()Deletes all files and directories in the temp root directory that have not been modified for about 11 hours (40,000 seconds).- Returns:
trueif all old entries were deleted
-
getLogDir
Returns the directory of the log files. It is the value of the system property "simplace.logdir" or, if not set,<user.home>/.simplace/log. The same rule is used by thelog4j2.xmlconfigurations, so the log never ends up in the (possibly read-only) current directory.- Returns:
- the log directory
-
getLogFile
- Returns:
- the log file
SIMPLACE.login thelog directory
-
getResourcePath
-