一般来说,我们使用Apache VFS时,直接从VFS对象获得的文件管理器是
StandardFileSystemManager,StandardFileSystemManager从DefaultFileSystemManager继承而来。而解析文件在
DefaultFileSystemManager中完成。
绝大部分时候,你会提供一个URI来定位你的文件系统,例如: ftp://yourftp/rootdir或者http://yourweb/rootdir或者file://c:/rootdir
,然后你将这个字符串作为参数传给StandardFileSystemManger, 这时候DefaultFileSystemManger的 resolveFile方法负责处理URI的解析,并且最终返回一个FileObject文件对象。我们看一下这个方法:
这个方法有5种重载方式,分别接受不同的参数,但核心方法只有一个:
/**
* 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);
}
绝大部分时候,你会提供一个URI来定位你的文件系统,例如: ftp://yourftp/rootdir或者http://yourweb/rootdir或者file://c:/rootdir
,然后你将这个字符串作为参数传给StandardFileSystemManger, 这时候DefaultFileSystemManger的 resolveFile方法负责处理URI的解析,并且最终返回一个FileObject文件对象。我们看一下这个方法:
这个方法有5种重载方式,分别接受不同的参数,但核心方法只有一个:
/**
* 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);
}