Navigation of this series of articles
Apache VFS (1): Basic Introduction
Apache VFS (2): file monitoring and monitoring
Apache VFS (3): file filter and Selector
Apache VFS (4): Events
Apache VFS (5): use it!
Apache VFS (6): several important conceptual Interfaces
Apache VFS (7): File Manager File Parsing Method
In general, when we use Apache VFS, the File Manager obtained directly from the VFS object isStandardFileSystemManager
, Standardfilesystemmanager is inherited from defaultfilesystemmanager. The parsing FileDefaultFileSystemManager
.
In most cases, you will provide a URI to locate your file system. For example:Ftp: // yourftp/rootdir or http: // yourweb/rootdi
R or file: // C:/rootdir
And pass the string as a parameter to standardfilesystemmanger.ResolveFile Method
Parses the URI and returns a fileobject object. Let's take a look at this method:
This method has five reload methods that accept different parameters, but the core method has only one:
/**
* Resolves a URI, realtive to a base file with specified filesystem
* Configuration
*/
Public FileObject resolveFile (final FileObject baseFile, final String uri,
Final FileSystemOptions fileSystemOptions)
Throws FileSystemException
{
Final FileObject realBaseFile;
If (baseFile! = Null & VFS. isUriStyle ()
& BaseFile. getName (). getType () = FileType. FILE)
{
RealBaseFile = baseFile. getParent ();
}
Else
{
Realbasefile = basefile;
}
// Todo: Use resolvename and use this name to resolve the fileobject
Uriparser. checkuriencoding (URI );
If (uri = NULL)
{
Throw new illegalargumentexception ();
}
// Extract the Scheme
Final string scheme = uriparser. extractscheme (URI );
If (scheme! = NULL)
{
// An absolute URI-locate the provider
Final fileprovider provider = (fileprovider) providers. Get (scheme );
If (provider! = NULL)
{
Return provider. findfile (realbasefile, Uri, filesystemoptions );
}
// Otherwise, assume a local file
}
// Handle absolute file names
If (localfileprovider! = NULL
& Localfileprovider. isabsolutelocalname (URI ))
{
Return localfileprovider. findlocalfile (URI );
}
If (scheme! = NULL)
{
// An unknown scheme-hand it to the default provider
If (defaultprovider = NULL)
{
Throw new FileSystemException ("vfs. impl/unknown-scheme.error ",
New Object []
{Scheme, uri });
}
Return defaultProvider. findFile (realBaseFile, uri,
FileSystemOptions );
}
// Assume a relative name-use the supplied base file
If (realBaseFile = null)
{
Throw new FileSystemException ("vfs. impl/find-rel-file.error", uri );
}
Return realBaseFile. resolveFile (uri );
}
Source: http://alartin.javaeye.com/blog/92436