Example usage for java.util.jar Attributes keySet

List of usage examples for java.util.jar Attributes keySet

Introduction

In this page you can find the example usage for java.util.jar Attributes keySet.

Prototype

public Set<Object> keySet() 

Source Link

Document

Returns a Set view of the attribute names (keys) contained in this Map.

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {
    JarFile jarfile = new JarFile("filename.jar");

    Manifest manifest = jarfile.getManifest();

    Attributes attrs = (Attributes) manifest.getMainAttributes();

    for (Iterator it = attrs.keySet().iterator(); it.hasNext();) {
        Attributes.Name attrName = (Attributes.Name) it.next();

        String attrValue = attrs.getValue(attrName);
    }/*from   ww  w  . j a  v  a  2 s . c  o m*/
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    JarFile jarfile = new JarFile("filename.jar", true);

    Manifest manifest = jarfile.getManifest();

    Attributes attrs = (Attributes) manifest.getMainAttributes();

    for (Iterator it = attrs.keySet().iterator(); it.hasNext();) {
        Attributes.Name attrName = (Attributes.Name) it.next();

        String attrValue = attrs.getValue(attrName);
    }//from  ww w  . j  av a  2s .c o  m
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    JarFile jarfile = new JarFile(new File("filename.jar"), true);

    Manifest manifest = jarfile.getManifest();

    Attributes attrs = (Attributes) manifest.getMainAttributes();

    for (Iterator it = attrs.keySet().iterator(); it.hasNext();) {
        Attributes.Name attrName = (Attributes.Name) it.next();

        String attrValue = attrs.getValue(attrName);
    }// w  w w . ja va 2s  .c  om
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    JarFile jarfile = new JarFile(new File("filename.jar"), true, JarFile.OPEN_READ);

    Manifest manifest = jarfile.getManifest();

    Attributes attrs = (Attributes) manifest.getMainAttributes();

    for (Iterator it = attrs.keySet().iterator(); it.hasNext();) {
        Attributes.Name attrName = (Attributes.Name) it.next();

        String attrValue = attrs.getValue(attrName);
    }/*from   w ww  .j ava  2s . c om*/
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    JarFile jarfile = new JarFile("filename.jar");

    Manifest manifest = jarfile.getManifest();

    Map map = manifest.getEntries();

    for (Iterator it = map.keySet().iterator(); it.hasNext();) {
        String entryName = (String) it.next();

        Attributes attrs = (Attributes) map.get(entryName);

        for (Iterator it2 = attrs.keySet().iterator(); it2.hasNext();) {
            Attributes.Name attrName = (Attributes.Name) it2.next();

            String attrValue = attrs.getValue(attrName);
        }/*from www  .  ja va2  s.  c o m*/
    }
}

From source file:adalid.util.info.JavaInfo.java

private static Map<String, Object> sort(Attributes attributes) {
    Object object;/* w ww  .  j  a v  a  2  s.  c o  m*/
    Map<String, Object> map = new TreeMap<>();
    for (Object key : attributes.keySet()) {
        object = attributes.get(key);
        map.put(key.toString(), object);
    }
    return map;
}

From source file:ezbake.deployer.utilities.VersionHelper.java

private static String getVersionFromManifest(File artifact) throws IOException {
    String versionNumber = null;/*from   w  w  w .  j  av  a  2s  .  co m*/
    try (JarFile jar = new JarFile(artifact)) {
        Manifest manifest = jar.getManifest();
        Attributes attributes = manifest.getMainAttributes();
        if (attributes != null) {
            for (Object o : attributes.keySet()) {
                Attributes.Name key = (Attributes.Name) o;
                String keyword = key.toString();
                if (keyword.equals("Implementation-Version") || keyword.equals("Bundle-Version")) {
                    versionNumber = (String) attributes.get(key);
                    break;
                }
            }
        }
    }
    return versionNumber;
}

From source file:edu.stanford.epad.common.plugins.impl.ClassFinderTestUtils.java

/**
 * //from www. j  a  v a2 s .  c o  m
 * @param clazz Class
 * @return String
 */
public static String readJarManifestForClass(Class<?> clazz) {
    StringBuilder sb = new StringBuilder();
    InputStream manifestInputStream = null;

    try {

        String className = clazz.getSimpleName() + ".class";
        String classPath = clazz.getResource(className).toString();
        if (!classPath.startsWith("jar")) {
            // Class not from JAR
            return "Class " + className + " not from jar file.";
        }

        String manifestPath = classPath.substring(0, classPath.lastIndexOf("!") + 1) + "/META-INF/MANIFEST.MF";
        manifestInputStream = new URL(manifestPath).openStream();
        Manifest manifest = new Manifest(manifestInputStream);
        Attributes attr = manifest.getMainAttributes();
        // String value = attr.getValue("Manifest-Version");

        Set<Object> keys = attr.keySet();
        for (Object currKey : keys) {
            String currValue = attr.getValue(currKey.toString());
            if (currValue != null) {
                sb.append(currKey.toString()).append(" : ").append(currValue).append("\n");
            } else {
                sb.append(currKey.toString()).append(": Didn't have a value");
            }
        }
    } catch (Exception e) {
        logger.warning("Failed to read manifest for " + clazz.getSimpleName(), e);
    } finally {
        IOUtils.closeQuietly(manifestInputStream);
    }
    return sb.toString();
}

From source file:net.sf.keystore_explorer.crypto.signing.JarSigner.java

private static String getManifestEntriesAttrs(JarFile jar) throws IOException {

    StringBuilder sbManifest = new StringBuilder();

    // Get current manifest
    Manifest manifest = jar.getManifest();

    // Write out entry attributes to manifest
    if (manifest != null) {
        // Get entry attributes
        Map<String, Attributes> entries = manifest.getEntries();

        boolean firstEntry = true;

        // For each entry...
        for (String entryName : entries.keySet()) {
            // Get entry's attributes
            Attributes entryAttrs = entries.get(entryName);

            // Completely ignore entries that contain only a xxx-Digest
            // attribute
            if ((entryAttrs.size() == 1) && (entryAttrs.keySet().toArray()[0].toString().endsWith("-Digest"))) {
                continue;
            }/*from   w  w w .ja  v a 2s .  c  om*/

            if (!firstEntry) {
                // Entries subequent to the first are split by a newline
                sbManifest.append(CRLF);
            }

            // Get entry attributes as a string to preserve their order
            String manifestEntryAttributes = getManifestEntryAttrs(jar, entryName);

            // Write them out
            sbManifest.append(manifestEntryAttributes);

            // The next entry will not be the first entry
            firstEntry = false;
        }
    }

    return sbManifest.toString();
}

From source file:com.qrmedia.commons.multispi.provider.ServiceClassnameAttributeProvider.java

@Override
protected boolean isManifestEntryOfImplementation(Attributes entryAttributes, Class<?> serviceClass) {
    return any(entryAttributes.keySet(),
            compose(new EqualToIgnoreCase(serviceClass.getSimpleName()), new Function<Object, String>() {
                public String apply(Object from) {
                    // the attributes map of a manifest entry contains keys of type Attributes.Name
                    return ((Name) from).toString();
                }//from   www . j  a v a 2s  .  c  o  m
            }));
}