zoukankan      html  css  js  c++  java
  • 从Eclipse插件中读取资源

    可以通过Eclipse里的OSGi的Bundle类,获取插件目录下的某个文件的输入流:
    1. Bundle bundle = Platform.getBundle(Activator.PLUGIN_ID);   
    2. URL url = bundle.getResource("/icon/xx.txt");   
    3. InputStream is = FileLocator.toFileURL(url).openStream();  

    从Bundle查找资源:
    Bundle bundle = Platform.getBundle(pluginId);
    URL fullpathString = BundleUtility.find(bundle, filePath);

    Enumeration org.osgi.framework.Bundle.findEntries(String path, String filePattern, boolean recurse)
    Returns entries in this bundle and its attached fragments. This bundle's
    class loader is not used to search for entries. Only the contents of this bundle
    and its attached fragments are searched for the specified entries. If this
    bundle's state is INSTALLED, this method must attempt to resolve
    this bundle before attempting to find entries.

    This method is intended to be used to obtain configuration, setup,
    localization and other information from this bundle. This method takes into
    account that the "contents" of this bundle can be extended with fragments. This
    "bundle space" is not a namespace with unique members; the same entry name can
    be present multiple times. This method therefore returns an enumeration of URL
    objects. These URLs can come from different JARs but have the same path name.
    This method can either return only entries in the specified path or recurse into
    subdirectories returning entries in the directory tree beginning at the
    specified path. Fragments can be attached after this bundle is resolved,
    possibly changing the set of URLs returned by this method. If this bundle is not
    resolved, only the entries in the JAR file of this bundle are returned.

    Examples:  // List all XML files in the OSGI-INF directory and below
     Enumeration e = b.findEntries("OSGI-INF", "*.xml", true);
     
     // Find a specific localization file
     Enumeration e = b
             .findEntries("OSGI-INF/l10n", "bundle_nl_DU.properties", false);
     if (e.hasMoreElements())
         return (URL) e.nextElement();
     
    Note: Jar and zip files are not required to include directory entries. URLs to directory entries will not be returned if the bundle contents do not contain directory entries. Parameters: path The path name in which to look. The path is always relative to the root of this bundle and may begin with "/". A path value of "/" indicates the root of this bundle. filePattern The file name pattern for selecting entries in the specified path. The pattern is only matched against the last element of the entry path. If the entry is a directory then the trailing "/" is not used for pattern matching. Substring matching is supported, as specified in the Filter specification, using the wildcard character ("*"). If null is specified, this is equivalent to "*" and matches all files. recurse If true, recurse into subdirectories. Otherwise only return entries from the specified path. Returns: An enumeration of URL objects for each matching entry, or null if an entry could not be found or if the caller does not have the appropriate AdminPermission[this,RESOURCE], and the Java Runtime Environment supports permissions. The URLs are sorted such that entries from this bundle are returned first followed by the entries from attached fragments in ascending bundle id order. If this bundle is a fragment, then only matching entries in this fragment are returned.

  • 相关阅读:
    判断输入的字符串是否含有特殊字符和表情
    表单转换为JSON
    重写Alert和confirm方法去除地址显示
    C语言内存管理
    自定义C语言中常用的字符串操作函数
    C语言中定义字符串的几种方式
    WebStorm常用快捷键
    鼠标点击特效
    打印指定年份的日历
    VS code 生成.exe可执行文件失效问题
  • 原文地址:https://www.cnblogs.com/hainange/p/6153620.html
Copyright © 2011-2022 走看看