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


Java Attributes.Name方法代码示例

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


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

示例1: get

import java.util.jar.Attributes; //导入方法依赖的package包/类
public @Override String get(Object _k) {
    if (!(_k instanceof String)) {
        return null;
    }
    String k = (String) _k;

    Attributes.Name an;

    try {
        an = new Attributes.Name(k);
    } catch (IllegalArgumentException iae) {
        // Robustness, and workaround for reported MRJ locale bug:
        LOG.log(Level.FINE, null, iae);
        return null;
    }

    return attrs.getValue(an);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:19,代码来源:NbBundle.java

示例2: 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

示例3: main

import java.util.jar.Attributes; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
    try {
        Attributes.Name name = new Attributes.Name("");
        throw new Exception("empty string should be rejected");
    } catch (IllegalArgumentException e) {
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:8,代码来源:Name.java

示例4: checkOrder

import java.util.jar.Attributes; //导入方法依赖的package包/类
static void checkOrder(Attributes.Name k0, String v0,
                       Attributes.Name k1, String v1,
                       Attributes.Name k2, String v2) {
    Attributes x = new Attributes();
    x.put(k0, v0);
    x.put(k1, v1);
    x.put(k2, v2);
    Map.Entry<?,?>[] entries
        = x.entrySet().toArray(new Map.Entry<?,?>[3]);
    if (!(entries.length == 3
          && entries[0].getKey() == k0
          && entries[0].getValue() == v0
          && entries[1].getKey() == k1
          && entries[1].getValue() == v1
          && entries[2].getKey() == k2
          && entries[2].getValue() == v2)) {
        throw new AssertionError(Arrays.toString(entries));
    }

    Object[] keys = x.keySet().toArray();
    if (!(keys.length == 3
          && keys[0] == k0
          && keys[1] == k1
          && keys[2] == k2)) {
         throw new AssertionError(Arrays.toString(keys));
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:28,代码来源:IterationOrder.java

示例5: main

import java.util.jar.Attributes; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
    Attributes.Name k0 = Name.MANIFEST_VERSION;
    Attributes.Name k1 = Name.MAIN_CLASS;
    Attributes.Name k2 = Name.SEALED;
    String v0 = "42.0";
    String v1 = "com.google.Hello";
    String v2 = "yes";
    checkOrder(k0, v0, k1, v1, k2, v2);
    checkOrder(k1, v1, k0, v0, k2, v2);
    checkOrder(k2, v2, k1, v1, k0, v0);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:12,代码来源:IterationOrder.java

示例6: writeAttribute

import java.util.jar.Attributes; //导入方法依赖的package包/类
static void writeAttribute(OutputStream  out, Attributes.Name name, String value)
        throws IOException {
    writeAttribute(out, name.toString(), value);
}
 
开发者ID:F8LEFT,项目名称:FApkSigner,代码行数:5,代码来源:ManifestWriter.java

示例7: getAttr

import java.util.jar.Attributes; //导入方法依赖的package包/类
private static String getAttr(Attributes spec, Attributes main, Attributes.Name name) {
    String val = null;
    if (spec != null) val = spec.getValue (name);
    if (val == null && main != null) val = main.getValue (name);
    return val;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:7,代码来源:PackageAttrsCache.java

示例8: checkZipFileForCertificate

import java.util.jar.Attributes; //导入方法依赖的package包/类
public static String checkZipFileForCertificate(String zipPath) throws IOException {
    String certPath = "";
    ZipFile zip = new ZipFile(new File(zipPath));

    // This call will throw a java.lang.SecurityException if someone has tampered
    // with the signature of _any_ element of the JAR file.
    // Alas, it will proceed without a problem if the JAR file is not signed at all
    InputStream is = zip.getInputStream(zip.getEntry("META-INF/MANIFEST.MF"));
    Manifest man = new Manifest(is);
    is.close();

    Set<String> signed = new HashSet();
    for (Map.Entry<String, Attributes> entry : man.getEntries().entrySet()) {
        for (Object attrkey : entry.getValue().keySet()) {
            if (attrkey instanceof Attributes.Name
                    && ((Attributes.Name) attrkey).toString().indexOf("-Digest") != -1)
                signed.add(entry.getKey());
        }
    }

    Set<String> entries = new HashSet<String>();
    for (Enumeration<ZipEntry> entry = (Enumeration<ZipEntry>) zip.entries(); entry.hasMoreElements();) {
        ZipEntry ze = entry.nextElement();
        if (!ze.isDirectory()) {
            String name = ze.getName();
            if (!name.startsWith("META-INF/")) {
                entries.add(name);
            } else if (name.endsWith(".RSA") || name.endsWith(".DSA")) {
                certPath = name;
            }
        }
    }

    // contains all entries in the Manifest that are not signed.
    // Ususally, this contains:
    // * MANIFEST.MF itself
    // * *.SF files containing the signature of MANIFEST.MF
    // * *.DSA files containing public keys of the signer

    Set<String> unsigned = new HashSet<String>(entries);
    unsigned.removeAll(signed);

    // contains all the entries with a signature that are not present in the JAR
    Set<String> missing = new HashSet<String>(signed);
    missing.removeAll(entries);
    zip.close();
    if (unsigned.isEmpty() && missing.isEmpty()) {
        return certPath;
    }
    return null;
}
 
开发者ID:didi,项目名称:VirtualAPK,代码行数:52,代码来源:ZipVerifyUtil.java

示例9: 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

示例10: 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

示例11: getAttributeValue

import java.util.jar.Attributes; //导入方法依赖的package包/类
/**
 * Returns the value of the specified attribute in this section or {@code null} if this
 * section does not contain a matching attribute.
 */
public String getAttributeValue(Attributes.Name name) {
    return getAttributeValue(name.toString());
}
 
开发者ID:F8LEFT,项目名称:FApkSigner,代码行数:8,代码来源:ManifestParser.java

示例12: getLocalizedValue

import java.util.jar.Attributes; //导入方法依赖的package包/类
/**
 * Find a localized and/or branded value in a JAR manifest.
* @param attr the manifest attributes
* @param key the key to look for (case-insensitive)
* @param locale the locale to use
* @return the value if found, else <code>null</code>
*/
public static String getLocalizedValue(Attributes attr, Attributes.Name key, Locale locale) {
    return getLocalizedValue(attr2Map(attr), key.toString().toLowerCase(Locale.US), locale);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:11,代码来源:NbBundle.java


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