当前位置: 首页>>代码示例>>Java>>正文


Java Attributes.keySet方法代码示例

本文整理汇总了Java中java.util.jar.Attributes.keySet方法的典型用法代码示例。如果您正苦于以下问题:Java Attributes.keySet方法的具体用法?Java Attributes.keySet怎么用?Java Attributes.keySet使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.jar.Attributes的用法示例。


在下文中一共展示了Attributes.keySet方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: apply

import java.util.jar.Attributes; //导入方法依赖的package包/类
public void apply() throws BundleException, IOException, CoreException {
	final String bundleSymbolicNameHeader = "Bundle-SymbolicName";
	Attributes mainAttrs = getManifest().getMainAttributes();
	String value = null;
	for (Object entryName : mainAttrs.keySet()) {
		String header;

		// Get the values safely
		if (entryName instanceof String) {
			header = (String) entryName;
			value = mainAttrs.getValue(header);
		} else if (entryName instanceof Attributes.Name) {
			header = (String) ((Attributes.Name) entryName).toString();
			value = mainAttrs.getValue((Attributes.Name) entryName);
		} else {
			throw new BundleException("Unknown Main Attribute Key type: "
					+ entryName.getClass() + " (" + entryName + ")");
		}

		// loop to the next header if we don't find ours
		if (bundleSymbolicNameHeader.equals(header)){
			break;
		}
	}
	if(value != null && !value.endsWith( ";singleton:=true")){
		// doesn't exist or already have it, so do not try to add the singleton ...
		getManifest().getMainAttributes().putValue(bundleSymbolicNameHeader,
				value + ";singleton:=true");
	}
}
 
开发者ID:eclipse,项目名称:gemoc-studio,代码行数:31,代码来源:ManifestChangerSingleton.java

示例2: add

import java.util.jar.Attributes; //导入方法依赖的package包/类
public void add(String packageName) throws BundleException, IOException, CoreException {
	final String exportPackageHeader = "Export-Package";
	
	boolean foundHeader = false;
	boolean hasValuesForPackageName = false;
	StringBuilder strBuilder = new StringBuilder();

	Attributes mainAttrs = getManifest().getMainAttributes();
	for (Object entryName : mainAttrs.keySet()) {
		String values;
		String header;

		// Get the values safely
		if (entryName instanceof String) {
			header = (String) entryName;
			values = mainAttrs.getValue(header);
		} else if (entryName instanceof Attributes.Name) {
			header = (String) ((Attributes.Name) entryName).toString();
			values = mainAttrs.getValue((Attributes.Name) entryName);
		} else {
			throw new BundleException("Unknown Main Attribute Key type: "
					+ entryName.getClass() + " (" + entryName + ")");
		}

		// loop to the next header if we don't find ours
		if (!exportPackageHeader.equals(header))
			continue;

		// found it
		foundHeader = true;

		// process the components of the value for this element see
		// ManifestElement javadocs for spec
		if (values != null) {
			ManifestElement[] elements = ManifestElement.parseHeader(
					header, values);
			for (int i = 0; i < elements.length; i++) {
				ManifestElement manifestElement = elements[i];

				boolean lastElement = i >= elements.length - 1;
				if(packageName.equals(manifestElement.getValueComponents()[0])){
					hasValuesForPackageName = true;
					break;
				}
				strBuilder.append(manifestElement.getValue());
				if (!lastElement) {
					strBuilder.append(",\n");
				}
			}
		}
	
		break;
	}
	if (!foundHeader) {
		// Add a new one with this package
		getManifest().getMainAttributes().putValue(
				exportPackageHeader,
				packageName);
	} else  {
		// found it and wish to edit it...
		if (!hasValuesForPackageName) {
			// There are no values for the package we wish to add.
			// ...create a fresh entry
			String existingValues = strBuilder.toString();
			boolean areExistingValues = existingValues.trim().length() != 0;
			String newValue = packageName ;
			newValue = (areExistingValues) ? (existingValues + ",\n " + newValue)
					: newValue;
			getManifest().getMainAttributes().putValue(exportPackageHeader,
					newValue);
		}
	}
}
 
开发者ID:eclipse,项目名称:gemoc-studio,代码行数:74,代码来源:ManifestChangerExportPackage.java

示例3: init

import java.util.jar.Attributes; //导入方法依赖的package包/类
private void init() throws IOException {
    Throwable th;
    JarFile jarFile = null;
    InputStream inputStream = null;
    try {
        JarFile jarFile2 = new JarFile(this.mFile);
        try {
            inputStream = jarFile2.getInputStream(jarFile2.getJarEntry(ENTRY_NAME));
            Attributes main = new Manifest(inputStream).getMainAttributes();
            this.mName = main.getValue(PATCH_NAME);
            this.mTime = new Date(main.getValue(CREATED_TIME));
            this.mClassesMap = new HashMap();
            for (Name attrName : main.keySet()) {
                String name = attrName.toString();
                if (name.endsWith(CLASSES)) {
                    List<String> strings = Arrays.asList(main.getValue(attrName).split(","));
                    if (name.equalsIgnoreCase(PATCH_CLASSES)) {
                        this.mClassesMap.put(this.mName, strings);
                    } else {
                        this.mClassesMap.put(name.trim().substring(0, name.length() - 8), strings);
                    }
                }
            }
            if (jarFile2 != null) {
                jarFile2.close();
            }
            if (inputStream != null) {
                inputStream.close();
            }
        } catch (Throwable th2) {
            th = th2;
            jarFile = jarFile2;
        }
    } catch (Throwable th3) {
        th = th3;
        if (jarFile != null) {
            jarFile.close();
        }
        if (inputStream != null) {
            inputStream.close();
        }
        throw th;
    }
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:45,代码来源:Patch.java

示例4: updateDigests

import java.util.jar.Attributes; //导入方法依赖的package包/类
private boolean updateDigests(ZipEntry ze, ZipFile zf,
                              MessageDigest[] digests,
                              Manifest mf) throws IOException {
    boolean update = false;

    Attributes attrs = mf.getAttributes(ze.getName());
    String[] base64Digests = getDigests(ze, zf, digests);

    for (int i = 0; i < digests.length; i++) {
        // The entry name to be written into attrs
        String name = null;
        try {
            // Find if the digest already exists. An algorithm could have
            // different names. For example, last time it was SHA, and this
            // time it's SHA-1.
            AlgorithmId aid = AlgorithmId.get(digests[i].getAlgorithm());
            for (Object key : attrs.keySet()) {
                if (key instanceof Attributes.Name) {
                    String n = key.toString();
                    if (n.toUpperCase(Locale.ENGLISH).endsWith("-DIGEST")) {
                        String tmp = n.substring(0, n.length() - 7);
                        if (AlgorithmId.get(tmp).equals(aid)) {
                            name = n;
                            break;
                        }
                    }
                }
            }
        } catch (NoSuchAlgorithmException nsae) {
            // Ignored. Writing new digest entry.
        }

        if (name == null) {
            name = digests[i].getAlgorithm() + "-Digest";
            attrs.putValue(name, base64Digests[i]);
            update = true;
        } else {
            // compare digests, and replace the one in the manifest
            // if they are different
            String mfDigest = attrs.getValue(name);
            if (!mfDigest.equalsIgnoreCase(base64Digests[i])) {
                attrs.putValue(name, base64Digests[i]);
                update = true;
            }
        }
    }
    return update;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:49,代码来源:JarSigner.java


注:本文中的java.util.jar.Attributes.keySet方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。