JarInputStreampublic class JarInputStream extends ZipInputStream The JarInputStream class is used to read the contents of
a JAR file from any input stream. It extends the class
java.util.zip.ZipInputStream with support for reading
an optional Manifest entry. The Manifest
can be used to store meta-information about the JAR file and its entries. |
Fields Summary |
---|
private Manifest | man | private JarEntry | first | private JarVerifier | jv | private ManifestEntryVerifier | mev |
Constructors Summary |
---|
public JarInputStream(InputStream in)Creates a new JarInputStream and reads the optional
manifest. If a manifest is present, also attempts to verify
the signatures if the JarInputStream is signed.
this(in, true);
| public JarInputStream(InputStream in, boolean verify)Creates a new JarInputStream and reads the optional
manifest. If a manifest is present and verify is true, also attempts
to verify the signatures if the JarInputStream is signed.
super(in);
JarEntry e = (JarEntry)super.getNextEntry();
if (e != null && e.getName().equalsIgnoreCase("META-INF/"))
e = (JarEntry)super.getNextEntry();
if (e != null && JarFile.MANIFEST_NAME.equalsIgnoreCase(e.getName())) {
man = new Manifest();
byte bytes[] = getBytes(new BufferedInputStream(this));
man.read(new ByteArrayInputStream(bytes));
//man.read(new BufferedInputStream(this));
closeEntry();
if (verify) {
jv = new JarVerifier(bytes);
mev = new ManifestEntryVerifier(man);
}
first = getNextJarEntry();
} else {
first = e;
}
|
Methods Summary |
---|
protected java.util.zip.ZipEntry | createZipEntry(java.lang.String name)Creates a new JarEntry (ZipEntry ) for the
specified JAR file entry name. The manifest attributes of
the specified JAR file entry name will be copied to the new
JarEntry .
JarEntry e = new JarEntry(name);
if (man != null) {
e.attr = man.getAttributes(name);
}
return e;
| private byte[] | getBytes(java.io.InputStream is)
byte[] buffer = new byte[8192];
ByteArrayOutputStream baos = new ByteArrayOutputStream(2048);
int n;
baos.reset();
while ((n = is.read(buffer, 0, buffer.length)) != -1) {
baos.write(buffer, 0, n);
}
return baos.toByteArray();
| public java.util.jar.Manifest | getManifest()Returns the Manifest for this JAR file, or
null if none.
return man;
| public java.util.zip.ZipEntry | getNextEntry()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.
JarEntry e;
if (first == null) {
e = (JarEntry)super.getNextEntry();
} else {
e = first;
first = null;
}
if (jv != null && e != null) {
// At this point, we might have parsed all the meta-inf
// entries and have nothing to verify. If we have
// nothing to verify, get rid of the JarVerifier object.
if (jv.nothingToVerify() == true) {
jv = null;
mev = null;
} else {
jv.beginEntry(e, mev);
}
}
return e;
| public java.util.jar.JarEntry | getNextJarEntry()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.
return (JarEntry)getNextEntry();
| public int | read(byte[] b, int off, int len)Reads from the current JAR file entry into an array of bytes.
Blocks until some input is available.
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.
int n;
if (first == null) {
n = super.read(b, off, len);
} else {
n = -1;
}
if (jv != null) {
jv.update(n, b, off, len, mev);
}
return n;
|
|