通过 HTTP 使用 Commons-VFS

发布于 2024-11-28 20:16:03 字数 1124 浏览 1 评论 0原文

我正在尝试使用 Commons VFS 来实现目录浏览功能,从 HTTP 服务器浏览和检索文件,在我的代码片段下面找到,

try {
    StandardFileSystemManager manager = new StandardFileSystemManager();
    manager.addProvider("http", new HttpFileProvider());
    manager.setCacheStrategy(CacheStrategy.ON_CALL);
    manager.setFilesCache(new SoftRefFilesCache());
    FileObject fileObject = manager.resolveFile("http://localhost");
    System.out.println(fileObject.getChildren());
} catch (FileSystemException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}

但是当我运行此代码时,出现以下异常,

org.apache.commons.vfs.FileSystemException: Could not list the contents of "http://localhost/" because it is not a folder.
at org.apache.commons.vfs.provider.AbstractFileObject.getChildren(AbstractFileObject.java:527)
at org.apache.commons.vfs.impl.DecoratedFileObject.getChildren(DecoratedFileObject.java:105)
at org.apache.commons.vfs.cache.OnCallRefreshFileObject.getChildren(OnCallRefreshFileObject.java:105)
at VFSClient.main(VFSClient.java:31)

但是服务器已启动并正在运行并且正在运行能够浏览目录。

谁能告诉我这个错误的原因是什么,我错过了什么吗?

I am trying to browse and retrieve files from an HTTP server using the Commons VFS to implement the directory browsing functionality, find below my code snippet,

try {
    StandardFileSystemManager manager = new StandardFileSystemManager();
    manager.addProvider("http", new HttpFileProvider());
    manager.setCacheStrategy(CacheStrategy.ON_CALL);
    manager.setFilesCache(new SoftRefFilesCache());
    FileObject fileObject = manager.resolveFile("http://localhost");
    System.out.println(fileObject.getChildren());
} catch (FileSystemException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}

But when i run this code i get the following exception,

org.apache.commons.vfs.FileSystemException: Could not list the contents of "http://localhost/" because it is not a folder.
at org.apache.commons.vfs.provider.AbstractFileObject.getChildren(AbstractFileObject.java:527)
at org.apache.commons.vfs.impl.DecoratedFileObject.getChildren(DecoratedFileObject.java:105)
at org.apache.commons.vfs.cache.OnCallRefreshFileObject.getChildren(OnCallRefreshFileObject.java:105)
at VFSClient.main(VFSClient.java:31)

But the server is up and running and am able to browse the directories.

Can anyone tell me what could be reason for this error, am I missing something ??

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

微暖i 2024-12-05 20:16:03

考虑在 FS2 上实现一个简单的具体存储库。 FS2 是一个中间件 API,可以处理文件系统中所需的所有 CRUD 等操作,但可以相对轻松地由任何持久性机制支持。

Consider implementing a simple concrete repo on FS2. FS2 is a middleware api that handles all the CRUD, etc operations you need in a filesystem but can be backed by any persistence mechanism relatively easily.

几度春秋 2024-12-05 20:16:03

HTTP 似乎不支持 LIST_CHILDREN:

fileObject.getFileSystem().hasCapability(Capability.LIST_CHILDREN)

会返回 false

您使用的 VFS 版本是什么?也许 v2.0 会有所帮助。文档是这样说的:
http://commons.apache.org/vfs/filesystems.html

HTTP seems not to support LIST_CHILDREN:

fileObject.getFileSystem().hasCapability(Capability.LIST_CHILDREN)

would return false

what version of VFS are you using? maybe v2.0 would help. The documentation says so:
http://commons.apache.org/vfs/filesystems.html

楠木可依 2024-12-05 20:16:03

与文档所述相反,我认为这尚未实现。看看 https://issues.apache.org/jira/browse/VFS-199

Contrary to what the documentation says, I don't think this is implemented yet. Take a look at https://issues.apache.org/jira/browse/VFS-199

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文