Code example for JarFile

Methods: getInputStream, getJarEntry

0
public class JarUtils { 
    @NonNls 
    public static final String MANIFEST_PATH = "META-INF/MANIFEST.MF";
 
    private static String getSpecificationVersion(JarFile jarFile) throws IOException {
        JarEntry jarEntry = jarFile.getJarEntry(MANIFEST_PATH);
        if (jarEntry == null) {
            return null; 
        } 
        final InputStream inputStream = jarFile.getInputStream(jarEntry);
        Manifest manifest;
        try { 
            manifest = new Manifest(inputStream);
        } finally { 
            inputStream.close();
        } 
 
        final String version = manifest.getAttributes("Play").getValue((Attributes.Name.SPECIFICATION_VERSION));
        if (version != null) {
            return version;
        }