本文整理汇总了Java中java.util.jar.Attributes.entrySet方法的典型用法代码示例。如果您正苦于以下问题:Java Attributes.entrySet方法的具体用法?Java Attributes.entrySet怎么用?Java Attributes.entrySet使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.jar.Attributes
的用法示例。
在下文中一共展示了Attributes.entrySet方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: assertTranslation
import java.util.jar.Attributes; //导入方法依赖的package包/类
private void assertTranslation(String expectedOsgi, String netbeans, Set<String> importedPackages, Set<String> exportedPackages) throws Exception {
assertTrue(netbeans.endsWith("\n")); // JRE bug
Manifest nbmani = new Manifest(new ByteArrayInputStream(netbeans.getBytes()));
Attributes nbattr = nbmani.getMainAttributes();
Manifest osgimani = new Manifest();
Attributes osgi = osgimani.getMainAttributes();
Info info = new Info();
info.importedPackages.addAll(importedPackages);
info.exportedPackages.addAll(exportedPackages);
new MakeOSGi().translate(nbattr, osgi, Collections.singletonMap(nbattr.getValue("OpenIDE-Module"), info));
// boilerplate:
assertEquals("1.0", osgi.remove(new Attributes.Name("Manifest-Version")));
assertEquals("2", osgi.remove(new Attributes.Name("Bundle-ManifestVersion")));
SortedMap<String,String> osgiMap = new TreeMap<>();
for (Map.Entry<Object,Object> entry : osgi.entrySet()) {
osgiMap.put(((Attributes.Name) entry.getKey()).toString(), (String) entry.getValue());
}
assertEquals(expectedOsgi, osgiMap.toString().replace('"', '\''));
}
示例2: getAttributesSortedByName
import java.util.jar.Attributes; //导入方法依赖的package包/类
static SortedMap<String, String> getAttributesSortedByName(Attributes attributes) {
Set<Map.Entry<Object, Object>> attributesEntries = attributes.entrySet();
SortedMap<String, String> namedAttributes = new TreeMap<String, String>();
for (Map.Entry<Object, Object> attribute : attributesEntries) {
String attrName = attribute.getKey().toString();
String attrValue = attribute.getValue().toString();
namedAttributes.put(attrName, attrValue);
}
return namedAttributes;
}
示例3: DummyModuleInfo
import java.util.jar.Attributes; //导入方法依赖的package包/类
/** Create a new fake module based on manifest.
* Only main attributes need be presented, so
* only pass these.
*/
public DummyModuleInfo(Attributes attr) throws IllegalArgumentException {
this.attr = attr;
if (attr == null) {
throw new IllegalArgumentException ("The parameter attr cannot be null.");
}
if (getCodeName() == null) {
throw new IllegalArgumentException ("No code name in module descriptor " + attr.entrySet ());
}
String cnb = getCodeNameBase();
try {
getSpecificationVersion();
} catch (NumberFormatException nfe) {
throw new IllegalArgumentException(nfe.toString() + " from " + cnb); // NOI18N
}
deps = parseDeps (attr, cnb);
// getAutoDepsHandler().refineDependencies(cnb, deps); // #29577
String providesS = attr.getValue("OpenIDE-Module-Provides"); // NOI18N
if (cnb.equals ("org.openide.modules")) { // NOI18N
providesS = providesS == null ? TOKEN_MODULE_FORMAT1 : providesS + ", " + TOKEN_MODULE_FORMAT1; // NOI18N
providesS = providesS == null ? TOKEN_MODULE_FORMAT2 : providesS + ", " + TOKEN_MODULE_FORMAT2; // NOI18N
}
if (providesS == null) {
provides = new String[0];
} else {
StringTokenizer tok = new StringTokenizer(providesS, ", "); // NOI18N
provides = new String[tok.countTokens()];
for (int i = 0; i < provides.length; i++) {
provides[i] = tok.nextToken();
}
}
// XXX could do more error checking but this is probably plenty
}
示例4: verifyManifestHash
import java.util.jar.Attributes; //导入方法依赖的package包/类
/**
* See if the whole manifest was signed.
*/
private boolean verifyManifestHash(Manifest sf,
ManifestDigester md,
List<Object> manifestDigests)
throws IOException, SignatureException
{
Attributes mattr = sf.getMainAttributes();
boolean manifestSigned = false;
// go through all the attributes and process *-Digest-Manifest entries
for (Map.Entry<Object,Object> se : mattr.entrySet()) {
String key = se.getKey().toString();
if (key.toUpperCase(Locale.ENGLISH).endsWith("-DIGEST-MANIFEST")) {
// 16 is length of "-Digest-Manifest"
String algorithm = key.substring(0, key.length()-16);
manifestDigests.add(key);
manifestDigests.add(se.getValue());
MessageDigest digest = getDigest(algorithm);
if (digest != null) {
byte[] computedHash = md.manifestDigest(digest);
byte[] expectedHash =
Base64.getMimeDecoder().decode((String)se.getValue());
if (debug != null) {
debug.println("Signature File: Manifest digest " +
digest.getAlgorithm());
debug.println( " sigfile " + toHex(expectedHash));
debug.println( " computed " + toHex(computedHash));
debug.println();
}
if (MessageDigest.isEqual(computedHash,
expectedHash)) {
manifestSigned = true;
} else {
//XXX: we will continue and verify each section
}
}
}
}
return manifestSigned;
}
示例5: verifyManifestMainAttrs
import java.util.jar.Attributes; //导入方法依赖的package包/类
private boolean verifyManifestMainAttrs(Manifest sf,
ManifestDigester md)
throws IOException, SignatureException
{
Attributes mattr = sf.getMainAttributes();
boolean attrsVerified = true;
// go through all the attributes and process
// digest entries for the manifest main attributes
for (Map.Entry<Object,Object> se : mattr.entrySet()) {
String key = se.getKey().toString();
if (key.toUpperCase(Locale.ENGLISH).endsWith(ATTR_DIGEST)) {
String algorithm =
key.substring(0, key.length() - ATTR_DIGEST.length());
MessageDigest digest = getDigest(algorithm);
if (digest != null) {
ManifestDigester.Entry mde =
md.get(ManifestDigester.MF_MAIN_ATTRS, false);
byte[] computedHash = mde.digest(digest);
byte[] expectedHash =
Base64.getMimeDecoder().decode((String)se.getValue());
if (debug != null) {
debug.println("Signature File: " +
"Manifest Main Attributes digest " +
digest.getAlgorithm());
debug.println( " sigfile " + toHex(expectedHash));
debug.println( " computed " + toHex(computedHash));
debug.println();
}
if (MessageDigest.isEqual(computedHash,
expectedHash)) {
// good
} else {
// we will *not* continue and verify each section
attrsVerified = false;
if (debug != null) {
debug.println("Verification of " +
"Manifest main attributes failed");
debug.println();
}
break;
}
}
}
}
// this method returns 'true' if either:
// . manifest main attributes were not signed, or
// . manifest main attributes were signed and verified
return attrsVerified;
}