查找 OSGI 包中的文件和文件夹
我正在编写必须在 osgi 环境中执行的测试用例,我已将测试数据(一组文件)放入测试包中。我可以使用bundle.getResource访问测试数据文件,它返回一个URL,从中我可以获取特定文件的InputStream,但是我如何找出测试插件中特定文件夹中的所有文件列表。在 eclispe 中,我可以使用 fileLocator 来执行此操作。
/捆绑
测试数据
one.txt
two.txt
三.txt
文件夹1
file1.txt
file2.txt
在上面的包中我想找到所有文件和文件夹存在于 testdata 文件夹中。
最佳雷兹,
克沙夫
I am writing test cases that have to be executed in osgi environment, i have put the test data which is a set of files in the test bundle. I am able to access the test data files using bundle.getResource which returns an URL from which i can get the InputStream for a particular file, but how can i find out all the list of files in a particular folder in the test plugin. In eclispe i could use fileLocator to do this.
/bundle
testdata
one.txt
two.txt
three.txt
folder1
file1.txt
file2.txt
In the above bundle i want to find all the files and folders that are present in the testdata folder.
Best Reards,
Keshav
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
类加载器访问的资源(类、文件、流等)可以由任何东西提供。通常,资源是从 JAR 文件加载的。但它也可以是数据库、文件系统或 HTTP 资源。因此,为了获取资源列表,您需要依赖类加载器背后的源。如果资源位于 JAR 内,您需要获取 JAR 本身并通过 java.util.zip 等访问它。由于 ClassLoader 接口不提供有关背后源的信息,因此您必须采取其他方式(例如挂钩到您使用的 OSGi 框架)。
Resources (classes, files, streams etc) accessed by the classloader can be provided by everything. Usually, resources are loaded from a JAR file. But it could be a database, a file system or a HTTP resource, too. So in order to get a list of resources, you depend on the source behind the classloader. In case the resources are located inside a JAR, you'll need to get the JAR itself and access it through e.g. java.util.zip. Since, the ClassLoader interface does not provide information about the source behind, you have to go other ways (like hooking into the OSGi framework you use).
如果您知道信息所在的包,请使用 Bundle.findEntries 或 Bundle.getEntryPaths。
If you know what bundle the information is in, use Bundle.findEntries or Bundle.getEntryPaths.