JarInputStream class, which extends ZipInputStream,
is used to read the contents of a JAR file from an input stream.
It provides support for reading an optional
Manifest
entry. The Manifest can be used to store
meta-information about the JAR file and its entries.
Unless otherwise noted, passing a null argument to a constructor
or method in this class will cause a NullPointerException to be
thrown.
The getManifest method is used to return the
Manifest
from the entry META-INF/MANIFEST.MF when it is the first entry
in the stream (or the second entry if the first entry in the stream is
META-INF/ and the second entry is META-INF/MANIFEST.MF).
The getNextJarEntry() and getNextEntry() methods are
used to read JAR file entries from the stream. These methods skip over the
Manifest (META-INF/MANIFEST.MF) when it is at the beginning of the
stream. In other words, these methods do not return an entry for the Manifest
when the Manifest is the first entry in the stream. If the first entry is
META-INF/ and the second entry is the Manifest then both are skipped
over by these methods. Whether these methods skip over the Manifest when it
appears later in the stream is not specified.
JarInputStream verifies the signatures of entries in a
Signed JAR file
when:
Manifest is the first entry in the stream (or the second
entry if the first entry in the stream is META-INF/ and the
second entry is META-INF/MANIFEST.MF).
Manifest
Once the JarEntry has been completely verified, which is done by
reading until the end of the entry's input stream,
JarEntry#getCertificates() may be called to obtain the certificates
for this entry and JarEntry#getCodeSigners() may be called to obtain
the signers.
It is important to note that the verification process does not include validating
the signer's certificate. A caller should inspect the return value of
JarEntry#getCodeSigners() to further determine if the signature
can be trusted.
API Note
If a JarEntry is modified after the JAR file is signed,
a SecurityException will be thrown when the entry is read.
Manifest, java.util.zip.ZipInputStream
| Modifier and Type | Field and Description |
|---|---|
| private final boolean | |
| private JarEntry | |
| private JarVerifier | |
| private Manifest | |
| private ManifestEntryVerifier | |
| private boolean |
| Access | Constructor and Description |
|---|---|
| public | JarInputStream(InputStream
the actual input stream in)Creates a new |
| public | JarInputStream(InputStream
the actual input stream in, boolean whether or not to verify the JarInputStream if
it is signed. verify)Creates a new |
| Modifier and Type | Method and Description |
|---|---|
| private JarEntry | |
| protected ZipEntry | Returns: theJarEntry object just createdthe name of the JAR/ZIP file entry name)Overrides java. Creates a new |
| public Manifest | Returns: theManifest for this JAR file, or
null otherwise.Returns the |
| public ZipEntry | getNextEntry()
Overrides java. Reads the next ZIP file entry and positions the stream at the beginning of the entry data. |
| public JarEntry | Returns: the next JAR file entry, or null if there are no more entriesReads the next JAR file entry and positions the stream at the beginning of the entry data. |
| public int | Returns: the actual number of bytes read, or -1 if the end of the entry is reachedthe buffer into which the data is read b, int the start offset in the destination array off, int bthe maximum number of bytes to read len)Overrides java. Reads from the current JAR entry into an array of bytes, returning the number of inflated bytes. |
| doVerify | back to summary |
|---|---|
| private final boolean doVerify | |
| first | back to summary |
|---|---|
| private JarEntry first | |
| jv | back to summary |
|---|---|
| private JarVerifier jv | |
| man | back to summary |
|---|---|
| private Manifest man | |
| mev | back to summary |
|---|---|
| private ManifestEntryVerifier mev | |
| tryManifest | back to summary |
|---|---|
| private boolean tryManifest | |
| JarInputStream | back to summary |
|---|---|
| public JarInputStream(InputStream in) throws IOException Creates a new
| |
| JarInputStream | back to summary |
|---|---|
| public JarInputStream(InputStream in, boolean verify) throws IOException Creates a new
| |
| checkManifest | back to summary |
|---|---|
| private JarEntry checkManifest(JarEntry e) throws IOException | |
| createZipEntry | back to summary |
|---|---|
| protected ZipEntry createZipEntry(String name) Overrides java. Creates a new | |
| getManifest | back to summary |
|---|---|
| public Manifest getManifest() Returns the
| |
| getNextEntry | back to summary |
|---|---|
| public ZipEntry getNextEntry() throws IOException Overrides java. Reads the next ZIP file entry and positions the stream at the beginning of the entry data. If verification has been enabled, any invalid signature detected while positioning the stream for the next entry will result in an exception.
| |
| getNextJarEntry | back to summary |
|---|---|
| public JarEntry getNextJarEntry() throws IOException Reads the next JAR file entry and positions the stream at the beginning of the entry data. If verification has been enabled, any invalid signature detected while positioning the stream for the next entry will result in an exception.
| |
| read | back to summary |
|---|---|
| public int read(byte[] b, int off, int len) throws IOException Overrides java. Reads from the current JAR entry into an array of bytes, returning the number of
inflated bytes. If
If the current entry is compressed and this method returns a nonzero
integer n then If verification has been enabled, any invalid signature on the current entry will be reported at some point before the end of the entry is reached.
| |