public class FileCluster
extends java.lang.Object
FileRemote
instances is used for the same string given path.
Different parts of the application can set some attributes in FileRemote, especially masks,
it is ensured that all usages get the same instance for the same path.
It means also that the properties of a file of the operation system should be read only one time for one Java application.
The access to the os file system is reduced. That is usefull especially for a remote file system.
But of course synchronizations due to changes of the file system's content is a topic.
The operation system's file properties should be synchronized with the FileRemote properties if necessary.
Modifier and Type | Class and Description |
---|---|
(package private) class |
FileCluster.ListSubdirs |
Modifier and Type | Field and Description |
---|---|
protected java.util.Map<java.lang.String,FileRemote> |
idxPaths
This index contains the association between paths and its FileRemote instances for all known directories.
|
static java.lang.String |
version
Version, history and license.
|
Constructor and Description |
---|
FileCluster() |
Modifier and Type | Method and Description |
---|---|
(package private) FileRemote |
getFile(java.lang.CharSequence sDirP,
java.lang.CharSequence sName)
Gets the existing file instance with this path from the file system or creates and registers a new one.
|
(package private) FileRemote |
getFile(java.lang.CharSequence sDirP1,
java.lang.CharSequence sName,
boolean assumeChild)
Gets the existing file instance with this path from the FileCluster or creates and registers a new one.
|
private void |
idxPathsput(java.lang.String key,
FileRemote value) |
java.util.Iterator<FileRemote> |
listSubdirs(java.lang.String startDir) |
private FileRemote |
searchOrCreateDir(java.lang.String sPath)
Searches a directory due to the given path.
|
public static final java.lang.String version
FileCluster.ListSubdirs
iterator was built for unchanged listSubdirs(String)
.
But listSubdirs(String)
is a little bit changed: It does not need to return a ListIterator,
a simple Iterator
is sufficient. This simplifies the FileCluster.ListSubdirs
.
idxPaths
contains paths in upper case for windows. There was sometimes irritations,
if a directory was given as String in faulty case, was found as file, and was contained twice here.
getFile(CharSequence, CharSequence, boolean)
and searchOrCreateDir(String)
builds upper case for search key.
FileRemote.getPathChars()
now returns a '/' on end,
but the paths in idxPaths
are stored without slash, some adaptions were necessary.
getFile(CharSequence, CharSequence, boolean)
: If the file was not found in the index,
the new private searchOrCreateDir(String)
is invoked instead immediately creating a new FileRemote instance.
That routine checks whether the parent is registered and whether the path describes a known FileRemote instance as child of parent.
Then that instance is used and registered. Because that routine is invoked recursively, the root will be found.
Either that is known, or the root is registered yet, especially on start. For that, all existing FileRemote instances should be re-found,
and never a new instance is created though one is exists.
getFile(CharSequence, CharSequence, boolean)
only FileFunctions.normalizePath(CharSequence)
is invoked. Not FileFunctions.getCanonicalPath(File)
: Reason: On this access the operation system's file system must not accessed.
Only an existing FileRemote
instance is searched and returned. Especially if a network directory is accessed and the
network is not accessible, this invocation must not hang! It is used in the graphic thread in the org.vishia.commander.
idxPaths
: fix: Check backward, therefore the IndexMultiTable#iterator(Comparable)
is a ListIterator
up to now.
FileRemote.isTested()
.
getFile(CharSequence, CharSequence, boolean)
checks whether a parent instance or deeper child instance is registered already and use that.
#check(CharSequence, CharSequence)
protected java.util.Map<java.lang.String,FileRemote> idxPaths
FileRemote.children
.
It is possible that a sub directory is referenced in children, but not registered here.
That is if it is itself not used with the content.FileRemote getFile(java.lang.CharSequence sDirP, java.lang.CharSequence sName)
FileRemote getFile(java.lang.CharSequence sDirP1, java.lang.CharSequence sName, boolean assumeChild)
sDirP
- String describes a directory. This string can have backslash instead slash and a non-normalized path (with .. etc.
First FileFunctions.normalizePath(CharSequence)
will be called with it.
It must be an absolute path without environment variable usage, asserted. The absolute path is not build here.sName
- If null then a directory is returned. If given then the returned instance is decided as a file.assumeChild
- true then check whether a requested directory is a child or sub child of a found parent directory.
It is possible to create a child without registration here for new files which are not decided as directory firstly.
FileRemote.child(CharSequence)
because that method calls this.
It creates the FileRemote directory instance in case of not found in the idxPaths
.FileRemote.refreshProperties()
may be necessary.private void idxPathsput(java.lang.String key, FileRemote value)
private FileRemote searchOrCreateDir(java.lang.String sPath)
sPath
- a directory pathpublic java.util.Iterator<FileRemote> listSubdirs(java.lang.String startDir)