Java.util.jar.JarInputStream class in Java Last Updated : 12 Sep, 2023 Comments Improve Suggest changes Like Article Like Report 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. Constructors 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. Methods: 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 Java //Java program demonstrating JarInputStream methods import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.util.Arrays; import java.util.jar.JarInputStream; import java.util.zip.ZipEntry; class JarInputStreamDemo extends JarInputStream { public JarInputStreamDemo(InputStream in) throws IOException { super(in); } public static void main(String[] args) throws IOException { FileInputStream is = new FileInputStream("codechecker.jar"); JarInputStream jis = new JarInputStream(is); JarInputStreamDemo obj=new JarInputStreamDemo(jis); //illustrating createZipEntry() method ZipEntry ze1=obj.createZipEntry("ZipEntry"); System.out.println(ze1.getName()); //illustrating getNextEntry() method ZipEntry ze=jis.getNextEntry(); System.out.println(ze.getName()); //illustrating getManifest(); System.out.println(jis.getManifest()); // Reading from the current JAR file entry // into an array of 10 bytes byte b[] = new byte[10]; //illustrating getNextJarEntry() //illustrating read(byte b[],int off,int length) while(jis.getNextJarEntry()!= null) jis.read(b); System.out.print(Arrays.toString(b)); //closing the stream jis.close(); } } Output : Zipentry Attention-64.png java.util.jar.Manifest@513ee0c5 [-119, 80, 78, 71, 13, 10, 26, 10, 0, 0] Comment More infoAdvertise with us Next Article Java.util.jar.JarInputStream class in Java N Nishant Sharma Improve Article Tags : Java Java-I/O Practice Tags : Java Similar Reads Java.util.jar.JarEntry class in Java This class is used to represent a JAR file entry. Constructors : JarEntry(JarEntry je) : Creates a new JarEntry with fields taken from the specified JarEntry object. JarEntry(String name) : Creates a new JarEntry for the specified JAR file entry name. JarEntry(ZipEntry ze) : Creates a new JarEntry w 2 min read Java.util.zip.InflaterInputStream class in Java This class implements a stream filter for uncompressing data in the "deflate" compression format. It is also used as the basis for other decompression filters, such as GZIPInputStream. Constructors InflaterInputStream(InputStream in) : Creates a new input stream with a default decompressor and buffe 3 min read Java.io.InputStream Class in Java Java InputStream class is the superclass of all the io classes i.e. representing an input stream of bytes. It represents an input stream of bytes. Applications that are defining a subclass of the Java InputStream class must provide a method, that returns the next byte of input. A reset() method is i 3 min read Java.util.zip.GZIPInputStream class in Java This class implements a stream filter for reading compressed data in the GZIP file format. Constructors GZIPInputStream(InputStream in) : Creates a new input stream with a default buffer size. GZIPInputStream(InputStream in, int size) : Creates a new input stream with the specified buffer size. Meth 2 min read Java.util.zip.InflaterOutputStream class in Java This class implements an output stream filter for uncompressing data stored in the "deflate" compression format. Constructors InflaterOutputStream(OutputStream out) : Creates a new output stream with a default decompressor and buffer size. InflaterOutputStream(OutputStream out, Inflater infl) : Crea 3 min read Java.util.zip.DeflaterInputStream class in Java Implements an input stream filter for compressing data in the "deflate" compression format. Constructor and Description DeflaterInputStream(InputStream in) : Creates a new input stream with a default compressor and buffer size. DeflaterInputStream(InputStream in, Deflater defl) : Creates a new input 3 min read Java.io.DataInputStream class in Java | Set 2 Java.io.DataInputStream class in Java | Set 1 More Methods: byte readByte() : Reads and returns one input byte. Syntax:public final byte readByte() throws IOException Returns: the next byte of this input stream as a signed 8-bit byte. Throws: EOFException IOException float readFloat() : Reads four i 3 min read Java.io.DataInputStream class in Java | Set 1 A data input stream enables an application to read primitive Java data types from an underlying input stream in a machine-independent way(instead of raw bytes). That is why it is called DataInputStream - because it reads data (numbers) instead of just bytes. An application uses a data output stream 3 min read Java.io.FilterInputStream Class in Java Filter Streams filters data as they read and write data in the Input Stream, filters it and pass it on to the underlying Streams. Filter Streams are FilterInputStream FilterOutput Stream FilterInputStream : Java.io.FilterInputStream class works almost like InputStream class in Java but what it does 9 min read InputStreamReader class in Java An InputStreamReader is a bridge from byte streams to character streams. It reads bytes and decodes them into characters using a specified charset. The charset that it uses may be specified by name or may be given explicitly, or the platform's default charset may be accepted. Declaration : public cl 4 min read Like