JarInputStream

JarInputStream is a subclass of ZipInputStream that reads data from JAR archives.

public class JarInputStream extends ZipInputStream

Two constructors chain the JAR input stream to an underlying input stream:

public JarInputStream(InputStream in) throws IOException public JarInputStream(InputStream in, boolean verify) throws IOException

By default, any signatures present in the JAR archive will be verified, and an IOException will be thrown if verification fails. However, you can turn off this behavior by passing false as the second argument to the constructor. For example:

FileInputStream fin = new FileInputStream("javaio.jar"); JarInputStream jin = new JarInputStream(fin, false);

When the JarInputStream object is constructed, the manifest, if present, is read from the stream and stored inside the class as a Manifest object. You do not get an opportunity to read the manifest from the stream yourself. However, you can retrieve the Manifest object with the getManifest( ) method:

public Manifest getManifest( )

Otherwise, a JAR input stream is used almost exactly like a zip input stream. You position the stream on a particular entry in the file and read data from it using the normal read( ) methods. Any necessary decompression is performed transparently. When you've finished reading an entry, you close it and position the stream on the next entry. Two methods, getNextEntry( ) and read( ), are overridden so that verification of signatures can be performed. A getNextJarEntry( ) method that returns a JarEntry instead of a ZipEntry is also available. This method can be used in place of getNextEnTRy( ), if you like:

public ZipEntry getNextEntry( ) throws IOException public int read(byte[] data, int offset, int length) throws IOException public JarEntry getNextJarEntry( ) throws IOException

Категории