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 static ContextLocal<FileSystemDaemon> |
instance
The singleton instance of this class
|
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 single)
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.
|
static FileSystemDaemon |
getInstance(boolean single)
Retrieve the target instance.
|
PathResolverContainer |
getLegacyPathResolver()
Gets the legacy path resolver.
|
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).
|
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.
|
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> exts)
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 java.lang.String[] paths
private boolean caseSens
private PathResolverContainer pathResolver
private FileSystemDaemon(boolean single)
single
- true
to startup within the server process which
must bypass the shared infrastructure initialization. Use
false
for the normal client JVM startup.public static FileSystemDaemon getInstance(boolean single)
single
- true
to startup within the server process which must bypass
the shared infrastructure initialization. Use false
for
the normal client JVM startup.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
.fileName
- A file name.File.separator
.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()
true
if the file system is case-sensitivepublic java.lang.String searchPathWithExts(java.lang.String filename, java.util.List<java.lang.String> exts)
filename
- The file name.exts
- The extensions to be checked.null
if not foundpublic FileInfo accessFileInfo(java.lang.String name)
accessFileInfo
in interface FileSystem
name
- The relative or absolute filename for which to obtain
information.public java.lang.String getRootList() throws java.io.IOException
getRootList
in interface FileSystem
java.io.IOException
public java.lang.String getProperty(java.lang.String key)
getProperty
in interface FileSystem
null
if the
property does not exist.public java.lang.String getFileSeparator()
getFileSeparator
in interface FileSystem
public java.lang.String getPathSeparator()
getPathSeparator
in interface FileSystem
public int mkdir(java.lang.String[] dirs)
mkdir
in interface FileSystem
dirs
- 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 FileSystem
source
- 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 FileSystem
paths
- 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.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 FileSystem
filename
- 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 FileSystem
source
- 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 FileSystem
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).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 FileSystem
list
- 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 FileSystem
filename
- 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 FileSystem
fileSeparator
- 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 PathResolverContainer getLegacyPathResolver()
public java.lang.String getWorkingDirectory()
getWorkingDirectory
in interface FileSystem
public void setWorkingDirectory(java.lang.String newWorkingDir)
setWorkingDirectory
in interface FileSystem
newWorkingDir
- A new working directory to set.private 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.