java.util.jar.Attributes.forEach()方法的使用及代码示例

x33g5p2x  于2022-01-15 转载在 其他  
字(1.7k)|赞(0)|评价(0)|浏览(116)

本文整理了Java中java.util.jar.Attributes.forEach()方法的一些代码示例,展示了Attributes.forEach()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Attributes.forEach()方法的具体详情如下:
包路径:java.util.jar.Attributes
类名称:Attributes
方法名:forEach

Attributes.forEach介绍

暂无

代码示例

代码示例来源:origin: com.yahoo.vespa/standalone-container

private Dictionary<String, String> retrieveHeaders(URL location) throws IOException {
    try (JarFile jarFile = new JarFile(location.getFile())) {
      Attributes attributes = jarFile.getManifest().getMainAttributes();
      Hashtable<String, String> ret = new Hashtable<>();
      attributes.forEach((k, v) -> ret.put(k.toString(), v.toString()));
      return ret;
    }
  }
}

代码示例来源:origin: waterguo/antsdb

public static Map<String, String> load(Class<?> klass) {
  Map<String, String> result = new HashMap<>();
  ClassLoader cl = klass.getClassLoader();
  String daklass = klass.getSimpleName() + ".class";
  URL daurl = klass.getResource(daklass);
  String prefix = StringUtils.substringBefore(daurl.toString(), "!");
  try {
    Enumeration<URL> it = cl.getResources("META-INF/MANIFEST.MF");
    while(it.hasMoreElements()) {
      URL url = it.nextElement();
      if (!url.toString().startsWith(prefix)) {
        continue;
      }
      Manifest manifest = new Manifest(url.openStream());
      manifest.getMainAttributes().forEach((key, attr) -> {
        result.put(key.toString(), attr.toString());
      });
      break;
    }
  } 
  catch (IOException x) {
  }
  return result;
}

代码示例来源:origin: wizzardo/http

protected void loadManifest(Config config) {
  Unchecked.ignore(() -> {
    Manifest manifest = new Manifest(WebApplication.class.getResourceAsStream("/META-INF/MANIFEST.MF"));
    Config subconfig = config.config("manifest");
    manifest.getMainAttributes().forEach((k, v) -> putInto(subconfig, String.valueOf(k), String.valueOf(v)));
  });
}

相关文章