public class FileSystemDaemon extends java.lang.Object implements FileSystem
Modifier and Type | Field and Description |
---|---|
private boolean |
caseSens
The legacy system's filesystem case-sensitivity.
|
private static java.lang.Object |
modToken
Token used to authenticate with the dispatcher when registering APIs.
|
private java.lang.String[] |
paths
Paths to search for relative filenames.
|
private static java.lang.String |
WIN_FILE_SEPARATOR
Windows 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
Constructor and Description |
---|
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 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.
|
private static java.lang.String |
getFileName(boolean caseSens,
boolean allowDir,
java.io.File file,
java.lang.String filename)
Return file name if file is valid
|
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 allowDir)
Return file name if file is valid in path
|
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).
|
boolean |
isCaseSensitive()
Check if the file system is case-sensitive
|
static boolean |
isPathRelativeToCurrentDir(java.lang.String pathName)
Utility method that checks if a path is in a form that is relative to the current dir
|
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.
|
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.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 file in paths with specified extensions
|
void |
setSearchPath(java.lang.String[] paths,
boolean caseSens)
Initializes the path for subsequent searches by
searchPath(java.lang.String) . |
private static final java.lang.String WIN_FILE_SEPARATOR
private static java.lang.Object modToken
private java.lang.String[] paths
private boolean caseSens
public 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 boolean isCaseSensitive()
true
if the file system is case-sensitivepublic 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.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 java.lang.String searchPathWithExts(java.lang.String filename, java.util.List<java.lang.String> exts)
filename
- file nameexts
- extensions to be checkednull
if not foundpublic 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).public 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 static boolean isPathRelativeToCurrentDir(java.lang.String pathName)
pathName
- The path which we want to check.true
if the path is in a form that is relative to current dir or
false
otherwisepublic static java.lang.String getEnvironmentValue(java.lang.String vname)
null
if variable
is currentlu not defined for given process.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 java.io.File repathSource(java.io.File source, java.lang.String target)
source
- The source file or directory.target
- The target directory (cannot be a file).private static java.lang.String getAbsoluteOrCurrent(boolean caseSens, java.lang.String filename, boolean allowDir)
caseSens
- true
if file system is case-sensitivefilename
- file to checkallowDir
- true
if directories are acceptedprivate static java.lang.String getInPath(boolean caseSens, java.lang.String path, java.lang.String filename, boolean allowDir)
caseSens
- true
if file system is case-sensitivepath
- path to be checkedallowDir
- true
if directories are acceptedfilename
- file to checkprivate static java.lang.String getFileName(boolean caseSens, boolean allowDir, java.io.File file, java.lang.String filename)
caseSens
- true
if file system is case-sensitiveallowDir
- true
if directories are acceptedfile
- file to be checkedfilename
- name to return