Apache VFS(7): 文件管理器解析文件的方法
来源:互联网 发布:乐视网络电视盒 编辑:程序博客网 时间:2024/05/20 03:05
本系列文章导航
Apache VFS(1): 基本介绍
Apache VFS(2): 文件的监听和监控
Apache VFS(3): 文件过滤器和选择器
Apache VFS(4): 事件
Apache VFS(5): 使用它!
Apache VFS(6): 几个重要的概念性接口
Apache VFS(7): 文件管理器解析文件的方法
一般来说,我们使用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);
}
文章来源:http://alartin.javaeye.com/blog/92436
- Apache VFS(7): 文件管理器解析文件的方法
- Apache VFS(2):文件的监听和监控
- Apache VFS(3): 文件过滤器和选择器
- Apache commons VFS 文件操作 源代码示例
- VFS 文件读写结构图
- VFS之文件操作
- 简单的文件管理器
- android4.4的文件管理器documentsui源码解析
- android4.4的文件管理器documentsui源码解析
- apache文件后缀名解析
- 解析XML文件的方法
- xml文件的解析方法
- 解析.txt文件的方法
- dbf文件的解析方法
- 让Apache支持shtml实现include文件解析的配置方法
- 文件管理器
- 文件管理器
- 文件管理器
- gridview 中文件头不换行
- Apache VFS(6): 几个重要的概念性接口
- 嵌入式研发工程师面试试题大全(ANSI CC++方面的知识 )
- python模块之smtplib: 用python发送SSL/TLS安全邮件
- C++库总结(zt)
- Apache VFS(7): 文件管理器解析文件的方法
- mysql远程访问的设置
- 清空vc watch窗口
- 国人关注的网站(点击进入)
- 所有login都不能登录,默认数据库离线导致
- 文本分类入门(三)统计学习方法
- 国人关注的主题(点击进入)
- csdn积分真难搞啊
- VB使用ActiveX控件实例和步聚