Java.util.jar.JarInputStream class in Java
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.
- JarInputStream(InputStream in) : Creates a new JarInputStream and reads the optional manifest.
- JarInputStream(InputStream in, boolean verify) : Creates a new JarInputStream and reads the optional manifest.
- protected ZipEntry createZipEntry(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.
- Manifest getManifest() : Returns the Manifest for this JAR file, or null if none.
Syntax :public Manifest getManifest() Returns: the Manifest for this JAR file, or null if none.
- 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.
Syntax :public ZipEntry getNextEntry() throws IOException Overrides: getNextEntry in class ZipInputStream Returns: the next ZIP file entry, or null if there are no more entries Throws: ZipException IOException SecurityException
- 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.
Syntax :public JarEntry getNextJarEntry() throws IOException Returns: the next JAR file entry, or null if there are no more entries Throws: ZipException IOException SecurityException
- int read(byte b, int off, int len) : Reads from the current JAR file entry into an array of bytes.If len is not zero, the method blocks until some input is available; otherwise, no bytes are read and 0 is returned. 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.
Syntax :public int read(byte b, int off, int len) throws IOException Overrides: read in class ZipInputStream Parameters: b - the buffer into which the data is read off - the start offset in the destination array b len - the maximum number of bytes to read Returns: the actual number of bytes read, or -1 if the end of the entry is reached Throws: NullPointerException IndexOutOfBoundsException ZipException IOException SecurityException
Zipentry Attention-64.png java.util.jar.Manifest@513ee0c5 [-119, 80, 78, 71, 13, 10, 26, 10, 0, 0]
This article is contributed by Nishant Sharma. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.