public class FileSystemDaemon extends java.lang.Object implements FileSystem
| Modifier and Type | Field and Description |
|---|---|
private static java.util.regex.Pattern |
anyPathSep
Regexp pattern for matching any path separators
|
private boolean |
caseSens
The legacy system's filesystem case-sensitivity.
|
private FileSystemResource |
fsRes
File system resource plugin
|
private static ContextLocal<FileSystemDaemon> |
instance
The singleton instance of this class
|
private boolean |
isServerSideFS
Cached server-side flag
|
private static boolean |
isWin
Flag to note if the rutnime platform for this JVM is Windows.
|
private static int |
MAXIMUM_FILE_TRANSFER_SIZE
Maximum size of file that can be transferred using
getFileContents(String), in
bytes. |
private static java.lang.Object |
modToken
Token used to authenticate with the dispatcher when registering APIs.
|
private PathResolverContainer |
pathResolver
The legacy path resolver
|
private java.lang.String[] |
paths
Paths to search for relative filenames.
|
ANY_PATH_SEPARATOR, ERR_BAD_ADDRESS, ERR_BAD_FILE_NUM, ERR_DIR_NOT_EMPTY, ERR_FILE_EXISTS, ERR_FILE_TABLE_OVERFLOW, ERR_FILE_TOO_LARGE, ERR_INTERRUPTED, ERR_IO, ERR_IS_DIR, ERR_NO_ERROR, ERR_NO_MORE_PROCESSES, ERR_NO_SPACE_ON_DEVICE, ERR_NO_SUCH_DEVICE, ERR_NO_SUCH_FILE_OR_DIR, ERR_NOT_DIR, ERR_NOT_ENOUGH_CORE, ERR_NOT_OWNER, ERR_PERM_DENIED, ERR_TOO_MANY_FILES, ERR_UNKNOWN| Modifier | Constructor and Description |
|---|---|
private |
FileSystemDaemon(boolean local,
boolean serverSideFS)
Create an instance and export its API to the network.
|
| Modifier and Type | Method and Description |
|---|---|
FileInfo |
accessFileInfo(java.lang.String name)
Access file system details regarding a specific file.
|
int |
copy(java.lang.String source,
java.lang.String target,
boolean overwrite)
Copies (or appends) the specified source file to or over the target
file.
|
static int |
delete(java.io.File target,
boolean recursive)
Deletes the specified file system entity, if necessary using recursion to delete all
contents (if it is a directory) first.
|
int |
delete(java.lang.String[] list,
boolean recursive)
Deletes each of the directories or files specified.
|
int |
delete(java.lang.String target,
boolean recursive)
Deletes the specified file system entity, if necessary using recursion
to delete all contents (if it is a directory) first.
|
private static int |
deleteWorker(java.io.File target,
boolean recursive)
Deletes the specified file system entity, if necessary using recursion
to delete all contents (if it is a directory) first.
|
private java.lang.String[] |
fixPathNames(java.lang.String[] pathNames)
Resolves the given legacy path names on the host system and updates them accordingly.
|
private static java.lang.String |
getAbsoluteOrCurrent(boolean caseSens,
java.lang.String filename,
boolean allowDir)
Return file name if it is absolute or exists in the current directory.
|
static java.lang.String |
getCaseInsensitiveMatch(java.io.File file,
boolean isDir)
Find the actual canonical filesystem name that matches the given file or
directory, if a case-insensitive match exists.
|
static java.lang.String |
getEnvironmentValue(java.lang.String vname)
Gets the OS environment variable value for given name if devined.
|
byte[] |
getFileContents(java.lang.String filename)
Get the file contents from the local file system.
|
private static java.lang.String |
getFileName(boolean caseSens,
boolean allowDir,
java.io.File file,
java.lang.String filename)
Return the given file name if file/directory exists and matches the given criteria.
|
java.lang.String |
getFileSeparator()
Get the file separator for the system.
|
private static java.lang.String |
getInPath(boolean caseSens,
java.lang.String path,
java.lang.String filename,
boolean allow)
Return the file name if the file is valid in the given path.
|
(package private) static FileSystemDaemon |
getInstance(boolean local,
boolean isServerSideFS)
Retrieve the target instance.
|
java.lang.String |
getPathSeparator()
Get the path separator for the system.
|
java.lang.String |
getProperty(java.lang.String key)
Get the system property (user-defined properties can be specified
at the Java command line) associated with the passed key.
|
java.lang.String |
getRootList()
Get the comma-separated list of filesystem roots (drive letters on
platforms that support the concept, otherwise returns the equivalent
of the empty string).
|
java.util.List<java.lang.String> |
getSearchPath()
Gets a copy of its search path.
|
java.lang.String |
getTempDirectory()
Gets the name of the directory where temporary files are stored.
|
static java.lang.String |
getWorkingDir()
Gets the working directory from OS.
|
java.lang.String |
getWorkingDirectory()
Gets the working directory.
|
boolean |
isCaseSensitive()
Check if the file system is case-sensitive
|
private static boolean |
isPathRelativeToCurrentDir(java.lang.String path)
Utility method that checks if a path is in a form that is relative to the current
directory.
|
int |
mkdir(java.lang.String[] dirs)
Creates each of the directories requested, if it doesn't exist and all
path segments up to the last segment do exist.
|
static java.lang.String |
normalizeFileSeparators(java.lang.String fileName)
Replaces UNIX-style and Windows-style file separators with
File.separator. |
int |
rename(java.lang.String source,
java.lang.String target)
Renames (and moves if the path is different) the specified source file
to the target filename (and path).
|
private java.io.File |
repathSource(java.io.File source,
java.lang.String target)
Takes the last part of the source filename (removes the path) and
appends this to the target directory name.
|
java.lang.String |
resolvePath(java.lang.String path)
Resolves the given path by the underlined path resolver, otherwise returns the given
unresolved value.
|
static java.lang.String |
search(java.lang.String[] paths,
boolean caseSens,
java.lang.String filename,
boolean allowDir)
Search for the given file in each directory listed in the paths specified.
|
static java.lang.String |
search(java.lang.String[] paths,
boolean caseSens,
java.lang.String filename,
boolean allowDir,
boolean searchAbsoluteOrRelativeOnly)
Search for the target path name.
|
static java.util.List<java.lang.String> |
searchAll(java.lang.String[] paths,
boolean caseSens,
java.lang.String filename,
boolean allowDir)
Return all files matching the specified
filename from each directory listed in the
paths specified. |
java.lang.String |
searchPath(java.lang.String filename)
Search for the given file in each directory listed in the path
previously specified via
setSearchPath(java.lang.String[], boolean). |
java.lang.String |
searchPathWithExts(java.lang.String filename,
java.util.List<java.lang.String> caseSensitiveExts,
java.util.List<java.lang.String> caseInsensitiveExts)
Search the current directory (and PROPATH if it is configured) for a given filename
with the specified extensions.
|
void |
setLegacyFileSystemParameters(java.lang.String fileSeparator,
boolean caseSensitive,
java.util.Map<java.lang.String,java.lang.String> pathMap,
java.lang.String[] paths,
boolean areLegacyPathsNotResolved)
Sets the legacy file system parameters to be used by the client.
|
void |
setSearchPath(java.lang.String[] paths,
boolean caseSens)
Initializes the path for subsequent searches by
searchPath(java.lang.String). |
static boolean |
setWorkingDir(java.lang.String newWorkingDir)
Sets the working directory via native OS call.
|
void |
setWorkingDirectory(java.lang.String newWorkingDir)
Sets the working directory via native OS call.
|
private static final java.util.regex.Pattern anyPathSep
private static final int MAXIMUM_FILE_TRANSFER_SIZE
getFileContents(String), in
bytes.private static final boolean isWin
private static final ContextLocal<FileSystemDaemon> instance
private static java.lang.Object modToken
private final boolean isServerSideFS
private java.lang.String[] paths
private boolean caseSens
private PathResolverContainer pathResolver
private FileSystemResource fsRes
private FileSystemDaemon(boolean local,
boolean serverSideFS)
local - true to register purely on a local basis (no remote/network access to these
methods).serverSideFS - true if the server-side file system is being used.static FileSystemDaemon getInstance(boolean local, boolean isServerSideFS)
local - true to register purely on a local basis (no remote/network access to these
methods).isServerSideFS - true if the server-side file system is being used.public static java.lang.String search(java.lang.String[] paths,
boolean caseSens,
java.lang.String filename,
boolean allowDir)
If the filename is specified as an absolute name, this specific filename is checked and no path searching is done.
paths - The list of paths to search. The file separator character used in these paths
should be the same as the current system's file separator character.caseSens - true if the search should honor a case-sensitive file-system. When set to
false and the current filesystem is naturally case-sensitive, a
case-insensitive search will be implemented.filename - The absolute or relative filename for which to search.allowDir - If true the search will also directories, if false only file
results will be returned.null is returned.public static java.lang.String search(java.lang.String[] paths,
boolean caseSens,
java.lang.String filename,
boolean allowDir,
boolean searchAbsoluteOrRelativeOnly)
paths - The list of paths to search. The file separator character used in these paths
should be the same as the current system's file separator character.caseSens - true if the search should honor a case-sensitive file-system. When set to
false and the current filesystem is naturally case-sensitive, a
case-insensitive search will be implemented.filename - The absolute or relative filename for which to search.allowDir - If true the search will also directories, if false only file
results will be returned.searchAbsoluteOrRelativeOnly - The true value indicates that the given absolute or relative path name is only
looked up, otherwise the given list of paths are used to look up the target path.null is returned.public static java.util.List<java.lang.String> searchAll(java.lang.String[] paths,
boolean caseSens,
java.lang.String filename,
boolean allowDir)
filename from each directory listed in the
paths specified. If the path list contains an empty string or a '.', then the
current directory is searched, otherwise only the listed directories are searched.
If the filename is specified as an absolute name, this specific filename is checked and no path searching is done and returned as a single element array.
paths - The list of paths to search. The file separator character used in these paths
should be the same as the current system's file separator character.caseSens - true if the search should honor a case-sensitive file-system. When set to
false and the current filesystem is naturally case-sensitive, a
case-insensitive search will be implemented.filename - The absolute or relative filename for which to search.allowDir - If true the search will also directories, if false only file(s)
results will be returned.String list.
If the file is absolute or found in any other path, the full absolute filename is
returned as a single element. If the file is not found or the referenced file
system object is not a file, null is returned.public static java.lang.String getEnvironmentValue(java.lang.String vname)
null if variable
is currentlu not defined for given process.public static java.lang.String getWorkingDir()
public static boolean setWorkingDir(java.lang.String newWorkingDir)
newWorkingDir - A new working directory to set.TRUE if success, FALSE otherwise.public static java.lang.String normalizeFileSeparators(java.lang.String fileName)
File.separator.
Also expands a file name that begins with "~/" to the user.home system property on UNIX platform.fileName - A file name.public static java.lang.String getCaseInsensitiveMatch(java.io.File file,
boolean isDir)
file - The filesystem object to search for.isDir - true if searching for a directory and
false if searching for a file.null if no such
object exists.public static int delete(java.io.File target,
boolean recursive)
target - The target file or directory to delete.recursive - Recursively decend through all subdirectories, deleting the entire subtree.ERR_NO_ERROR if no problems occur).private static int deleteWorker(java.io.File target,
boolean recursive)
target - The target file or directory to delete.recursive - Recursively decend through all subdirectories, deleting
the entire subtree.ERR_NO_ERROR if no problems
occur).private static boolean isPathRelativeToCurrentDir(java.lang.String path)
path - The path to check. No call to normalizeFileSeparators(java.lang.String) will be made. It
is assumed this is already normalized.true if the path is in a form that is relative to current directory
or false otherwise.private static java.lang.String getAbsoluteOrCurrent(boolean caseSens,
java.lang.String filename,
boolean allowDir)
caseSens - true if file system is case-sensitivefilename - The file to check. No call to normalizeFileSeparators(java.lang.String) will be made. It
is assumed this is already normalized.allowDir - true if directories are acceptedprivate static java.lang.String getInPath(boolean caseSens,
java.lang.String path,
java.lang.String filename,
boolean allow)
caseSens - true if file system is case-sensitivepath - The path to be checked. This will be normalized before processing by calling
normalizeFileSeparators(java.lang.String).allow - true if directories are accepted.filename - The file to check. No call to normalizeFileSeparators(java.lang.String) will be made. It
is assumed this is already normalized.private static java.lang.String getFileName(boolean caseSens,
boolean allowDir,
java.io.File file,
java.lang.String filename)
caseSens - true if file system is case-sensitive.allowDir - true if directories are accepted.file - The file to be checked.filename - The name to return if it exists and matches the rest of the criteria.
No call to normalizeFileSeparators(java.lang.String) will be made. It is
assumed this is already normalized.public boolean isCaseSensitive()
isCaseSensitive in interface FileSystemtrue if the file system is case-sensitivepublic java.lang.String searchPathWithExts(java.lang.String filename,
java.util.List<java.lang.String> caseSensitiveExts,
java.util.List<java.lang.String> caseInsensitiveExts)
searchPathWithExts in interface FileSystemfilename - The file name.caseSensitiveExts - The extensions to be checked if the file system is case-sensitive.caseInsensitiveExts - The extensions to be checked if the file system is case-insensitive.null if not foundpublic FileInfo accessFileInfo(java.lang.String name)
accessFileInfo in interface FileSystemname - The relative or absolute filename for which to obtain
information.public java.lang.String getRootList()
throws java.io.IOException
getRootList in interface FileSystemjava.io.IOExceptionpublic java.lang.String getProperty(java.lang.String key)
getProperty in interface FileSystemnull if the
property does not exist.public java.lang.String getFileSeparator()
getFileSeparator in interface FileSystempublic java.lang.String getPathSeparator()
getPathSeparator in interface FileSystempublic int mkdir(java.lang.String[] dirs)
mkdir in interface FileSystemdirs - The list of directories to create.ERR_NO_ERROR if no problems
occur).public int rename(java.lang.String source,
java.lang.String target)
rename in interface FileSystemsource - The name of the source file or directory.target - The name of the target file or directory. If this is a
directory name for a directory that already exists and the
source is a file, then the source file name will
be used as the target file in the directory given.ERR_NO_ERROR if no problems
occur).public void setSearchPath(java.lang.String[] paths,
boolean caseSens)
searchPath(java.lang.String).setSearchPath in interface FileSystempaths - The list of paths to search for files specified by relative
filename.caseSens - true if the legacy system had a case-sensitive
file-system.public java.util.List<java.lang.String> getSearchPath()
getSearchPath in interface FileSystempublic java.lang.String searchPath(java.lang.String filename)
setSearchPath(java.lang.String[], boolean). If the file system
object exists and is a file, then the filename is returned. If the path
contains an empty string or a '.', then the current directory is
searched, otherwise only the listed directories are searched.
If the filename is specified as an absolute name, this specific filename is checked and no path searching is done.
searchPath in interface FileSystemfilename - The absolute or relative filename for which to search.null is returned.public int copy(java.lang.String source,
java.lang.String target,
boolean overwrite)
overwrite parameter. If any error occurs, no exception
will be thrown.copy in interface FileSystemsource - The name of the source file. Must NOT be a directory name.
Must be an existing file.target - The name of the target file. If this is a directory name,
the source file name will be used as the target file in
the directory given.overwrite - If true this is a copy, otherwise it is an
append.ERR_NO_ERROR if no problems
occur).public int delete(java.lang.String target,
boolean recursive)
delete in interface FileSystemtarget - The target file or directory to delete.recursive - Recursively decend through all subdirectories, deleting
the entire subtree.ERR_NO_ERROR if no problems
occur).public int delete(java.lang.String[] list,
boolean recursive)
recursive flag is true. If any error occurs,
no exception will be thrown, the deletion process just continues. The
last error will be the one returned even if there were prior successful
deletes or other failures.delete in interface FileSystemlist - The list of files and directories to delete.recursive - Recursively decend through all subdirectories, deleting
the entire subtree.ERR_NO_ERROR if no problems
occur).public byte[] getFileContents(java.lang.String filename)
throws java.io.IOException
getFileContents in interface FileSystemfilename - Name of the file in the client-side file system (relatively to the current
directory on the client side).java.io.IOException - If the file cannot not be found or read, or if it is too large.public void setLegacyFileSystemParameters(java.lang.String fileSeparator,
boolean caseSensitive,
java.util.Map<java.lang.String,java.lang.String> pathMap,
java.lang.String[] paths,
boolean areLegacyPathsNotResolved)
setLegacyFileSystemParameters in interface FileSystemfileSeparator - The legacy file separatorcaseSensitive - The legacy case sensitive modepathMap - The legacy path mappaths - The list of paths to search for files specified by relative
filename.areLegacyPathsNotResolved - The true value of this parameter indicates that legacy path names must be resolved
on the host system, and false value means that legacy path names are not required
to be resolved.public java.lang.String resolvePath(java.lang.String path)
FileSystemresolvePath in interface FileSystempath - The given path to be resolvedpublic java.lang.String getWorkingDirectory()
getWorkingDirectory in interface FileSystempublic void setWorkingDirectory(java.lang.String newWorkingDir)
setWorkingDirectory in interface FileSystemnewWorkingDir - A new working directory to set.public java.lang.String getTempDirectory()
SESSION:TEMP-DIRECTORY system handle attribute.getTempDirectory in interface FileSystemprivate java.lang.String[] fixPathNames(java.lang.String[] pathNames)
pathNames - The given legacy path namesprivate java.io.File repathSource(java.io.File source,
java.lang.String target)
source - The source file or directory. No call to normalizeFileSeparators(java.lang.String)
will be made. It is assumed this is already normalized.target - The target directory (cannot be a file). No call to
normalizeFileSeparators(java.lang.String) will be made. It is assumed this is already
normalized.