sys.util.jar.Manifest.getAttributes()

Here are the examples of the java api sys.util.jar.Manifest.getAttributes() taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

1 Examples 7

15 View Source File : ZipSigner.java , License : Apache License 2.0 , Project Creator : SnowVolf
/**
 * Add the SHA1 of every file to the manifest, creating it if necessary.
 */
private Manifest addDigestsToManifest(Map<String, ZioEntry> entries) throws IOException, GeneralSecurityException {
    Manifest input = null;
    ZioEntry manifestEntry = entries.get(JarFile.MANIFEST_NAME);
    if (manifestEntry != null) {
        input = new Manifest();
        input.read(manifestEntry.getInputStream());
    }
    Manifest output = new Manifest();
    Attributes main = output.getMainAttributes();
    if (input != null) {
        main.putAll(input.getMainAttributes());
    } else {
        main.putValue("Manifest-Version", "1.0");
        main.putValue("Created-By", "1.0 (Android SignApk)");
    }
    // BASE64Encoder base64 = new BASE64Encoder();
    MessageDigest md = MessageDigest.getInstance("SHA1");
    byte[] buffer = new byte[512];
    int num;
    // We sort the input entries by name, and add them to the
    // output manifest in sorted order.  We expect that the output
    // map will be deterministic.
    TreeMap<String, ZioEntry> byName = new TreeMap<String, ZioEntry>();
    byName.putAll(entries);
    boolean debug = getLogger().isDebugEnabled();
    if (debug)
        getLogger().debug("Manifest entries:");
    for (ZioEntry entry : byName.values()) {
        if (canceled)
            break;
        String name = entry.getName();
        if (debug)
            getLogger().debug(name);
        if (!entry.isDirectory() && !name.equals(JarFile.MANIFEST_NAME) && !name.equals(CERT_SF_NAME) && !name.equals(CERT_RSA_NAME) && (stripPattern == null || !stripPattern.matcher(name).matches())) {
            progressHelper.progress(ProgressEvent.PRORITY_NORMAL, resourceAdapter.getString(ResourceAdapter.Item.GENERATING_MANIFEST));
            InputStream data = entry.getInputStream();
            while ((num = data.read(buffer)) > 0) {
                md.update(buffer, 0, num);
            }
            Attributes attr = null;
            if (input != null) {
                sys.util.jar.Attributes inAttr = input.getAttributes(name);
                if (inAttr != null)
                    attr = new Attributes(inAttr);
            }
            if (attr == null)
                attr = new Attributes();
            attr.putValue("SHA1-Digest", Base64.encode(md.digest()));
            output.getEntries().put(name, attr);
        }
    }
    return output;
}