Introduction
The java.util.zip Error contains the error which can occur during zip/unzip operations.
Interface Summary
| Sr.No. | Error & Description |
|---|---|
| 1 | ZipErrorSignals that an unrecoverable error has occurred. |
https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcR3KTh3wGipdhva2iT4Urby8_N1SNDVlrunA2h9k_CFXfUDnU5Uybjs09bAcC4a39Hrg7w
The java.util.zip Error contains the error which can occur during zip/unzip operations.
| Sr.No. | Error & Description |
|---|---|
| 1 | ZipErrorSignals that an unrecoverable error has occurred. |
The java.util.zip Exceptions contains the exceptions which can occur during zip/unzip operations.
| Sr.No. | Exception & Description |
|---|---|
| 1 | DataFormatExceptionSignals that a data format error has occurred. |
| 2 | ZipExceptionSignals that a Zip exception of some sort has occurred. |
The java.util.zip.ZipOutputStream class implements an output stream filter for writing files in the ZIP file format. Includes support for both compressed and uncompressed entries.
Following is the declaration for java.util.zip.ZipOutputStream class −
publicclassZipOutputStreamextendsDeflaterOutputStream
Learn Java in-depth with real-world projects through our Java certification course. Enroll and become a certified expert to boost your career.
Following are the fields for java.util.zip.ZipOutputStream class −
| Sr.No. | Constructor & Description |
|---|---|
| 1 | ZipOutputStream(OutputStream out)Creates a new ZIP output stream. |
| 2 | ZipOutputStream(OutputStream out, Charset charset)Creates a new ZIP output stream. |
| Sr.No. | Method & Description |
|---|---|
| 1 | void close()Closes the ZIP output stream as well as the stream being filtered. |
| 2 | void closeEntry()Closes the current ZIP entry and positions the stream for writing the next entry. |
| 3 | void finish()Finishes writing the contents of the ZIP output stream without closing the underlying stream. |
| 4 | void putNextEntry(ZipEntry e)Begins writing a new ZIP file entry and positions the stream to the start of the entry data. |
| 5 | void setComment(String comment)Sets the ZIP file comment. |
| 6 | void setLevel(int level)Sets the compression level for subsequent entries which are DEFLATED. |
| 7 | void setMethod(int method)Sets the default compression method for subsequent entries. |
| 8 | void write(byte[] b, int off, int len)Writes an array of bytes to the current ZIP entry data. |
This class inherits methods from the following classes −
The java.util.zip.ZipInputStream class implements an input stream filter for reading files in the ZIP file format. Includes support for both compressed and uncompressed entries.
Following is the declaration for java.util.zip.ZipInputStream class −
publicclassZipInputStreamextendsInflaterInputStream
Learn Java in-depth with real-world projects through our Java certification course. Enroll and become a certified expert to boost your career.
Following are the fields for java.util.zip.ZipInputStream class −
| Sr.No. | Constructor & Description |
|---|---|
| 1 | ZipInputStream(InputStream in)Creates a new ZIP input stream. |
| 2 | ZipInputStream(InputStream in, Charset charset)Creates a new ZIP input stream. |
| Sr.No. | Method & Description |
|---|---|
| 1 | int available()Returns 0 after EOF has reached for the current entry data, otherwise always return 1. |
| 2 | void close()Closes this input stream and releases any system resources associated with the stream. |
| 3 | void closeEntry()Closes the current ZIP entry and positions the stream for reading the next entry. |
| 4 | ZipEntry getNextEntry()Reads the next ZIP file entry and positions the stream at the beginning of the entry data. |
| 5 | int read(byte[] b, int off, int len)Reads from the current ZIP entry into an array of bytes. |
| 6 | long skip(long n)Skips specified number of bytes in the current ZIP entry. |
This class inherits methods from the following classes −
The java.util.zip.ZipFile class is used to read entries from a zip file.
Following is the declaration for java.util.zip.ZipFile class −
publicclassZipFileextendsObjectimplementsCloseable
Learn Java in-depth with real-world projects through our Java certification course. Enroll and become a certified expert to boost your career.
Following are the fields for java.util.zip.ZipFile class −
| Sr.No. | Constructor & Description |
|---|---|
| 1 | ZipFile(File file)Opens a ZIP file for reading given the specified File object. |
| 2 | ZipFile(File file, Charset charset)Opens a ZIP file for reading given the specified File object. |
| 3 | ZipFile(File file, int mode)Opens a new ZipFile to read from the specified File object in the specified mode. |
| 4 | ZipFile(File file, int mode, Charset charset)Opens a new ZipFile to read from the specified File object in the specified mode. |
| 5 | ZipFile(String name)Opens a zip file for reading. |
| 6 | ZipFile(String name, Charset charset)Opens a zip file for reading. |
| Sr.No. | Method & Description |
|---|---|
| 1 | void close()Closes the ZIP file. |
| 2 | Enumeration<? extends ZipEntry> entries()Returns an enumeration of the ZIP file entries. |
| 3 | String getComment()Returns the zip file comment, or null if none. |
| 4 | ZipEntry getEntry(String name)Returns the zip file entry for the specified name, or null if not found. |
| 5 | InputStream getInputStream(ZipEntry entry)Returns an input stream for reading the contents of the specified zip file entry. |
| 6 | String getName()Returns the path name of the ZIP file. |
| 7 | int size()Returns the number of entries in the ZIP file. |
This class inherits methods from the following classes −
The java.util.zip.ZipEntry class is used to represent a ZIP file entry.
Following is the declaration for java.util.zip.ZipEntry class −
publicclassZipEntryextendsObjectimplementsCloneable
Learn Java in-depth with real-world projects through our Java certification course. Enroll and become a certified expert to boost your career.
Following are the fields for java.util.zip.ZipEntry class −
| Sr.No. | Constructor & Description |
|---|---|
| 1 | ZipEntry(String name)Creates a new zip entry with the specified name. |
| 2 | ZipEntry(ZipEntry e)Creates a new zip entry with fields taken from the specified zip entry. |
| Sr.No. | Method & Description |
|---|---|
| 1 | Object clone()Returns a copy of this entry. |
| 2 | String getComment()Returns the comment string for the entry, or null if none. |
| 3 | long getCompressedSize()Returns the size of the compressed entry data, or -1 if not known. |
| 4 | long getCrc()Returns the CRC-32 checksum of the uncompressed entry data, or -1 if not known. |
| 5 | byte[] getExtra()Returns the extra field data for the entry, or null if none. |
| 6 | int getMethod()Returns the compression method of the entry, or -1 if not specified. |
| 7 | String getName()Returns the name of the entry. |
| 8 | long getSize()Returns the uncompressed size of the entry data, or -1 if not known. |
| 9 | long getTime()Returns the modification time of the entry, or -1 if not specified. |
| 10 | int hashCode()Returns the hash code value for this entry. |
| 11 | boolean isDirectory()Returns true if this is a directory entry. |
| 12 | void setComment(String comment)Sets the optional comment string for the entry. |
| 13 | void setCrc(long crc)Sets the CRC-32 checksum of the uncompressed entry data. |
| 14 | void setExtra(byte[] extra)Sets the optional extra field data for the entry. |
| 15 | void setMethod(int method)Sets the compression method for the entry. |
| 16 | void setSize(long size)Sets the uncompressed size of the entry data. |
| 17 | void setTime(long time)Sets the modification time of the entry. |
| 18 | String toString()Returns a string representation of the ZIP entry. |
This class inherits methods from the following classes −
The java.util.zip.InflaterOutputStream class implements an output stream filter for uncompressing data stored in the “deflate” compression format.
Following is the declaration for java.util.zip.InflaterOutputStream class −
publicclassInflaterOutputStreamextendsFilterOutputStream
Learn Java in-depth with real-world projects through our Java certification course. Enroll and become a certified expert to boost your career.
Following are the fields for java.util.zip.InflaterOutputStream class −
| Sr.No. | Constructor & Description |
|---|---|
| 1 | InflaterOutputStream(OutputStream out)Creates a new output stream with a default decompressor and buffer size. |
| 2 | InflaterOutputStream(OutputStream out, Inflater infl)Creates a new output stream with the specified decompressor and a default buffer size. |
| 3 | InflaterOutputStream(OutputStream out, Inflater infl, int bufLen)Creates a new output stream with the specified decompressor and buffer size. |
| Sr.No. | Method & Description |
|---|---|
| 1 | void close()Writes remaining compressed data to the output stream and closes the underlying stream. |
| 2 | void finish()Finishes writing uncompressed data to the output stream without closing the underlying stream. |
| 3 | void flush()Flushes this output stream, forcing any pending buffered output bytes to be written. |
| 4 | void write(byte[] b, int off, int len)Writes an array of bytes to the compressed output stream. |
| 5 | void write(int b)Writes a byte to the compressed output stream. |
This class inherits methods from the following classes −
The java.util.zip.InflaterInputStream 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.
Following is the declaration for java.util.zip.InflaterInputStream class −
publicclassInflaterInputStreamextendsFilterInputStream
Learn Java in-depth with real-world projects through our Java certification course. Enroll and become a certified expert to boost your career.
Following are the fields for java.util.zip.InflaterInputStream class −
| Sr.No. | Constructor & Description |
|---|---|
| 1 | InflaterInputStream(InputStream in)Creates a new input stream with a default decompressor and buffer size. |
| 2 | InflaterInputStream(InputStream in, Inflater inf)Creates a new input stream with the specified decompressor and a default buffer size. |
| 3 | InflaterInputStream(InputStream in, Inflater inf, int size)Creates a new input stream with the specified decompressor and buffer size. |
| Sr.No. | Method & Description |
|---|---|
| 1 | int available()Returns 0 after EOF has been reached, otherwise always return 1. |
| 2 | void close()Closes this input stream and releases any system resources associated with the stream. |
| 3 | void mark(int readlimit)Marks the current position in this input stream. |
| 4 | boolean markSupported()Tests if this input stream supports the mark and reset methods. |
| 5 | int read()Reads a byte of uncompressed data. |
| 6 | int read(byte[] b, int off, int len)Reads uncompressed data into an array of bytes. |
| 7 | void reset()Repositions this stream to the position at the time the mark method was last called on this input stream. |
| 8 | long skip(long n)Skips specified number of bytes of uncompressed data. |
This class inherits methods from the following classes −
The java.util.zip.Inflater class provides support for general purpose decompression using the popular ZLIB compression library. The ZLIB compression library was initially developed as part of the PNG graphics standard and is not protected by patents. It is fully described in the specifications at the java.util.zip package description.
Following is the declaration for java.util.zip.Inflater class −
publicclassInflaterextendsObject
Learn Java in-depth with real-world projects through our Java certification course. Enroll and become a certified expert to boost your career.
| Sr.No. | Constructor & Description |
|---|---|
| 1 | Inflater()Creates a new decompressor. |
| 2 | Inflater(boolean nowrap)Creates a new decompressor. |
| Sr.No. | Method & Description |
|---|---|
| 1 | void end()Closes the decompressor and discards any unprocessed input. |
| 2 | boolean finished()Returns true if the end of the compressed data stream has been reached. |
| 3 | int getAdler()Returns the ADLER-32 value of the uncompressed data. |
| 4 | long getBytesRead()Returns the total number of compressed bytes input so far. |
| 5 | long getBytesWritten()Returns the total number of uncompressed bytes output so far. |
| 6 | int getRemaining()Returns the total number of bytes remaining in the input buffer. |
| 7 | int getTotalIn()Returns the total number of compressed bytes input so far. |
| 8 | int getTotalOut()Returns the total number of uncompressed bytes output so far. |
| 9 | int inflate(byte[] b)Uncompresses bytes into specified buffer. |
| 10 | int inflate(byte[] b, int off, int len)Uncompresses bytes into specified buffer. |
| 11 | boolean needsDictionary()Returns true if a preset dictionary is needed for decompression. |
| 12 | boolean needsInput()Returns true if no data remains in the input buffer. |
| 13 | void reset()Resets inflater so that a new set of input data can be processed. |
| 14 | void setDictionary(byte[] b)Sets the preset dictionary to the given array of bytes. |
| 15 | void setDictionary(byte[] b, int off, int len)Sets the preset dictionary to the given array of bytes. |
| 16 | void setInput(byte[] b)Sets input data for decompression. |
| 17 | void setInput(byte[] b, int off, int len)Sets input data for decompression. |
This class inherits methods from the following classes −
The java.util.zip.GZIPOutputStream class implements a stream filter for writing compressed data in the GZIP file format.
Following is the declaration for java.util.zip.GZIPOutputStream class −
publicclassGZIPOutputStreamextendsDeflaterOutputStream
Learn Java in-depth with real-world projects through our Java certification course. Enroll and become a certified expert to boost your career.
Following are the fields for java.util.zip.GZIPOutputStream class −
| Sr.No. | Constructor & Description |
|---|---|
| 1 | GZIPOutputStream(OutputStream out)Creates a new output stream with a default buffer size. |
| 2 | GZIPOutputStream(OutputStream out, boolean syncFlush)Creates a new output stream with a default buffer size and the specified flush mode. |
| 3 | GZIPOutputStream(OutputStream out, int size)Creates a new output stream with the specified buffer size. |
| 4 | GZIPOutputStream(OutputStream out, int size, boolean syncFlush)Creates a new output stream with the specified buffer size and flush mode. |
| Sr.No. | Method & Description |
|---|---|
| 1 | void finish()Finishes writing compressed data to the output stream without closing the underlying stream. |
| 2 | int write(byte[] buf, int off, int len)Writes array of bytes to the compressed output stream. |
This class inherits methods from the following classes −