查找 OSGI 包中的文件和文件夹

发布于 2024-09-19 13:58:49 字数 686 浏览 2 评论 0原文

我正在编写必须在 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 技术交流群。

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

发布评论

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

评论(2

む无字情书 2024-09-26 14:00:08

类加载器访问的资源(类、文件、流等)可以由任何东西提供。通常,资源是从 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).

屋檐 2024-09-26 13:59:49

如果您知道信息所在的包,请使用 Bundle.findEntries 或 Bundle.getEntryPaths。

If you know what bundle the information is in, use Bundle.findEntries or Bundle.getEntryPaths.

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