/** * Returns the {@code Manifest} object associated with this {@code JarFile} or {@code null} if no * MANIFEST entry exists. * * @return the MANIFEST. * @throws IOException if an error occurs reading the MANIFEST file. * @throws IllegalStateException if the jar file is closed. * @see Manifest */ public Manifest getManifest() throws IOException { if (closed) { // archive.35=JarFile has been closed throw new IllegalStateException(Messages.getString("archive.35")); // $NON-NLS-1$ } if (manifest != null) { return manifest; } try { InputStream is = super.getInputStream(manifestEntry); if (verifier != null) { verifier.addMetaEntry(manifestEntry.getName(), getAllBytesFromStreamAndClose(is)); is = super.getInputStream(manifestEntry); } try { manifest = new Manifest(is, verifier != null); } finally { is.close(); } manifestEntry = null; // Can discard the entry now. } catch (NullPointerException e) { manifestEntry = null; } return manifest; }
/** * Called by the JarFile constructors, this method reads the contents of the file's META-INF/ * directory and picks out the MANIFEST.MF file and verifier signature files if they exist. Any * signature files found are registered with the verifier. * * @throws IOException if there is a problem reading the jar file entries. */ private void readMetaEntries() throws IOException { // Get all meta directory entries ZipEntry[] metaEntries = getMetaEntriesImpl(); if (metaEntries == null) { verifier = null; return; } boolean signed = false; for (ZipEntry entry : metaEntries) { String entryName = entry.getName(); // Is this the entry for META-INF/MANIFEST.MF ? if (manifestEntry == null && Util.asciiEqualsIgnoreCase(MANIFEST_NAME, entryName)) { manifestEntry = entry; // If there is no verifier then we don't need to look any further. if (verifier == null) { break; } } else { // Is this an entry that the verifier needs? if (verifier != null && (Util.asciiEndsWithIgnoreCase(entryName, ".SF") || Util.asciiEndsWithIgnoreCase(entryName, ".DSA") || Util.asciiEndsWithIgnoreCase(entryName, ".RSA"))) { signed = true; InputStream is = super.getInputStream(entry); byte[] buf = getAllBytesFromStreamAndClose(is); verifier.addMetaEntry(entryName, buf); } } } // If there were no signature files, then no verifier work to do. if (!signed) { verifier = null; } }