Returns the main Attributes for the JAR file for this
connection.

@return the main Attributes for the JAR file for this
connection.

@exception IOException if getting the manifest causes an
IOException to be thrown.

@see #getJarFile
@see #getManifest
762598
public Attributes getMainAttributes() throws IOException {
        Manifest man = getManifest();
        return man != null ? man.getMainAttributes() : null;
    }
109442
protected String resolveJarFile() {
        Class resourceClass = resourceInfo.getResourceClass();
        if (resourceClass == null) return null;
        String classFile = resourceClass.getName().replace(".", "/") + ".class";
        URL classUrl = IOUtils.getResource(classFile);
        String urlProtocol = classUrl.getProtocol();
        if (urlProtocol.equals("jar")) {
            String path = classUrl.getPath();
            return path.substring(0, path.length() - classFile.length() - 1);
        }
        return null;
    }
574721
public synchronized JarFile getNestedJarFile(JarEntryData sourceEntry)
            throws IOException {
        try {
            if (sourceEntry.nestedJar == null) {
                sourceEntry.nestedJar = createJarFileFromEntry(sourceEntry);
            }
            return sourceEntry.nestedJar;
        } catch (IOException ex) {
            throw new IOException(
                    "Unable to open nested jar file '" + sourceEntry.getName() + "'", ex);
        }
    }
319536
public static String jarVersion(JarFile jar) throws IOException {
		String version = jar.getManifest().getMainAttributes().getValue(Attributes.Name.IMPLEMENTATION_VERSION);
		
		if(version == null) {
			version = String.format("%d", System.currentTimeMillis());
		}
		return version;
	}
689019
private byte[] getSignature(final Manifest forManifest) throws IOException, GeneralSecurityException {

		final ByteArrayOutputStream bos = new ByteArrayOutputStream();
		final Manifest signatureFile    = new Manifest();
		final Attributes main           = signatureFile.getMainAttributes();
		final MessageDigest md          = MessageDigest.getInstance("SHA1");
		final PrintStream print         = new PrintStream(new DigestOutputStream(new ByteArrayOutputStream(), md), true, "UTF-8");

		main.putValue("Signature-Version", "1.0");

		// Digest of the entire manifest
		forManifest.write(print);
		print.flush();

		main.putValue("SHA1-Digest-Manifest", new String(Base64.encode(md.digest()), "ASCII"));

		final Map<String, Attributes> entries = forManifest.getEntries();

		for (Map.Entry<String, Attributes> entry : entries.entrySet()) {

			// Digest of the manifest stanza for this entry.
			print.print("Name: " + entry.getKey() + "\r\n");

			for (Map.Entry<Object, Object> att : entry.getValue().entrySet()) {
				print.print(att.getKey() + ": " + att.getValue() + "\r\n");
			}

			print.print("\r\n");
			print.flush();

			final Attributes sfAttr = new Attributes();
			sfAttr.putValue("SHA1-Digest", new String(Base64.encode(md.digest()), "ASCII"));

			signatureFile.getEntries().put(entry.getKey(), sfAttr);
		}

		signatureFile.write(bos);

		return bos.toByteArray();
	}
812921
public HashMap<String, String> getManifestAttributes()
    {
        HashMap<String,String> attributes = new HashMap<String,String>();

        if ( _intfDecl == null )
            return attributes;

        try
        {
            ManifestAttributes annotAttrs =_intfDecl.getAnnotation(ManifestAttributes.class);
            if (annotAttrs != null)
            {
                ManifestAttribute [] attrs = (ManifestAttribute [])annotAttrs.value();
                for (int i = 0; i < attrs.length; i++)
                {
                    if (isValidManifestAttribute(attrs[i]))
                        attributes.put(attrs[i].name(), attrs[i].value());
                }
            }
            ManifestAttribute annotAttr = _intfDecl.getAnnotation(ManifestAttribute.class);
            if (annotAttr != null)
            {
                if (isValidManifestAttribute(annotAttr))
                    attributes.put(annotAttr.name(), annotAttr.value());
            }
            return attributes;
        }
        catch (Exception e) { e.printStackTrace(); return attributes; }
    }
123204
@Override
    public List<URL> getJarFileUrls()
    {
        return jarUrls != null ? new ArrayList<URL>(jarUrls) : null;
    }
1059539
public static Manifest readManifest(VirtualFile manifest) throws IOException {
        if (manifest == null) {
            throw MESSAGES.nullArgument("manifest file");
        }
        InputStream stream = new PaddedManifestStream(manifest.openStream());
        try {
            return new Manifest(stream);
        } finally {
            safeClose(stream);
        }
    }
1368655
public static URL[] getLibJars(Configuration conf) throws IOException {
    String jars = conf.get("tmpjars");
    if(jars==null) {
      return null;
    }
    String[] files = jars.split(",");
    URL[] cp = new URL[files.length];
    for (int i=0;i<cp.length;i++) {
      Path tmp = new Path(files[i]);
      cp[i] = FileSystem.getLocal(conf).pathToFile(tmp).toURI().toURL();
    }
    return cp;
  }
1157698
private static InternetHeaders getManifestProperties(File manifest) {
        final InternetHeaders result = new InternetHeaders();
        if (null == manifest) {
            LOGGER.debug("Manifest file not found.");
        } else {
            try (InputStream in = new BufferedInputStream(new FileInputStream(manifest))) {
                result.load(in);
            } catch (MessagingException | FileNotFoundException e) {
                LOGGER.warn(e.getMessage(), e);
            } catch (IOException ex) {
                LOGGER.warn(ex.getMessage(), ex);
            }
        }
        return result;
    }
945058
private JarFile getJarFile(String jarFileUrl) throws IOException {
        if (jarFileUrl.startsWith("file:")) {
            try {
                final URI uri = new URI(jarFileUrl.replaceAll(" ", "\\%20"));
                final String jarFileName = uri.getSchemeSpecificPart();
                logger.info("Creating new JarFile based on URI-scheme filename: {}", jarFileName);
                return new JarFile(jarFileName);
            } catch (URISyntaxException ex) {
                // Fallback for URLs that are not valid URIs (should hardly ever
                // happen).
                final String jarFileName = jarFileUrl.substring("file:".length());
                logger.info("Creating new JarFile based on alternative filename: {}", jarFileName);
                return new JarFile(jarFileName);
            }
        } else {
            logger.info("Creating new JarFile based on URI (with '!/'): {}", jarFileUrl);
            return new JarFile(jarFileUrl);
        }
    }
1112482
@Override
    public InputStream getInputStream() throws IOException {
        if (closed) {
            throw new IllegalStateException("JarURLConnection InputStream has been closed");
        }
        connect();
        if (jarInput != null) {
            return jarInput;
        }
        if (jarEntry == null) {
            throw new IOException("Jar entry not specified");
        }
        return jarInput = new JarURLConnectionInputStream(jarFile
                .getInputStream(jarEntry), jarFile);
    }
1211633
private File getJarPath() {
        String decodedPath = ".";
        String jarPath = "";
        final ProtectionDomain domain = Settings.class.getProtectionDomain();
        if (domain != null && domain.getCodeSource() != null && domain.getCodeSource().getLocation() != null) {
            jarPath = Settings.class.getProtectionDomain().getCodeSource().getLocation().getPath();
        }
        try {
            decodedPath = URLDecoder.decode(jarPath, StandardCharsets.UTF_8.name());
        } catch (UnsupportedEncodingException ex) {
            LOGGER.trace("", ex);
        }

        final File path = new File(decodedPath);
        if (path.getName().toLowerCase().endsWith(".jar")) {
            return path.getParentFile();
        } else {
            return new File(".");
        }
    }
1284961
public static String[] getAllClassPathNotInJar() {
        String[] allClassPath = getAllClassPaths();
        List<String> allClassPathNotInJar = new ArrayList<String>();
        for (String classPath : allClassPath) {
            if (classPath.endsWith("jar")) {
                continue;
            }
            allClassPathNotInJar.add(classPath);
        }
        return allClassPathNotInJar.toArray(new String[allClassPathNotInJar.size()]);
    }
531367
List<File> findNonJdkJars() throws IOException, SAXException, XPathExpressionException, ParserConfigurationException {
        Enumeration<URL> manifests = LibraryVersions.class.getClassLoader().getResources("META-INF/MANIFEST.MF");
        String javaHome = System.getProperty("java.home");
        List<File> ret = new LinkedList<File>();
        while (manifests.hasMoreElements()) {
            URL u = manifests.nextElement();
            // jar:file:/home/username/.m2/repository/org/slf4j/slf4j-jdk14/1.5.0/slf4j-jdk14-1.5.0.jar!/META-INF/MANIFEST.MF
            // we're not interested if it's not a jar, although how you'd have a MANIFEST.MF which wasn't in a jar?
            if (u.getProtocol().equals("jar")) {
                // file:/home/username/.m2/repository/com/betfair/tornjak/kpi/3.0-SNAPSHOT/kpi-3.0-SNAPSHOT.jar!/META-INF/MANIFEST.MF
                String file = u.getFile();
                // file:/home/username/.m2/repository/com/betfair/tornjak/kpi/3.0-SNAPSHOT/kpi-3.0-SNAPSHOT.jar
                file = file.substring(0, file.indexOf("!"));
                // /home/username/.m2/repository/com/betfair/tornjak/kpi/3.0-SNAPSHOT/kpi-3.0-SNAPSHOT.jar
                file = file.substring(5);
                // remove %20 etc
                file = URLDecoder.decode(file, "UTF-8");
                File f = new File(file);
                String canonicalPath = f.getCanonicalPath();
                if (!canonicalPath.startsWith(javaHome)) {
                    ret.add(f);
                }
            } else {
                logger.info("Can't include code in checksum which isn't in a JAR: " + u);
            }
        }
        return ret;
    }
1194884
public static String jarVersion(Class<?> jarClass) {
    String j2objcVersion = null;

    String path = jarClass.getProtectionDomain().getCodeSource().getLocation().getPath();
    try (JarFile jar = new JarFile(URLDecoder.decode(path, "UTF-8"))) {
      Manifest manifest = jar.getManifest();
      j2objcVersion = manifest.getMainAttributes().getValue("version");
    } catch (IOException e) {
      // fall-through
    }
    if (j2objcVersion == null) {
      j2objcVersion = "(j2objc version not available)";
    }

    String javacVersion = Parser.newParser(null).version();
    return String.format("%s (javac %s)", j2objcVersion, javacVersion);
  }
1286817
public static String findMainClass(JarFile jarFile, String classesLocation)
			throws IOException {
		return doWithMainClasses(jarFile, classesLocation, MainClass::getName);
	}