| java.lang.Object | ||||
| ↳ | java.io.InputStream | |||
| ↳ | java.io.FilterInputStream | |||
| ↳ | java.util.zip.InflaterInputStream | |||
| ↳ | java.util.zip.ZipInputStream | |||
|  Known Direct Subclasses | 
This class provides an implementation of FilterInputStream that decompresses data from an InputStream containing a ZIP archive. 
A ZIP archive is a collection of (possibly) compressed files. When reading from a ZipInputStream, you retrieve the entry's metadata with getNextEntry before you can read the userdata. 
Although InflaterInputStream can only read compressed ZIP archive entries, this class can read non-compressed entries as well. 
Use ZipFile if you can access the archive as a file directly, especially if you want random access to entries, rather than needing to iterate over all entries. 
Using ZipInputStream is a little more complicated than GZIPInputStream because ZIP archives are containers that can contain multiple files. This code pulls all the files out of a ZIP archive, similar to the unzip(1) utility. 
 InputStream is = ...
 ZipInputStream zis = new ZipInputStream(new BufferedInputStream(is));
 try {
     ZipEntry ze;
     while ((ze = zis.getNextEntry()) != null) {
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
         byte[] buffer = new byte[1024];
         int count;
         while ((count = zis.read(buffer)) != -1) {
             baos.write(buffer, 0, count);
         }
         String filename = ze.getName();
         byte[] bytes = baos.toByteArray();
         // do something with 'filename' and 'bytes'...
     }
 } finally {
     zis.close();
 }
 
       
       
     | Constants | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| int | CENATT | ||||||||||
| int | CENATX | ||||||||||
| int | CENCOM | ||||||||||
| int | CENCRC | ||||||||||
| int | CENDSK | ||||||||||
| int | CENEXT | ||||||||||
| int | CENFLG | ||||||||||
| int | CENHDR | ||||||||||
| int | CENHOW | ||||||||||
| int | CENLEN | ||||||||||
| int | CENNAM | ||||||||||
| int | CENOFF | ||||||||||
| long | CENSIG | ||||||||||
| int | CENSIZ | ||||||||||
| int | CENTIM | ||||||||||
| int | CENVEM | ||||||||||
| int | CENVER | ||||||||||
| int | ENDCOM | ||||||||||
| int | ENDHDR | ||||||||||
| int | ENDOFF | ||||||||||
| long | ENDSIG | ||||||||||
| int | ENDSIZ | ||||||||||
| int | ENDSUB | ||||||||||
| int | ENDTOT | ||||||||||
| int | EXTCRC | ||||||||||
| int | EXTHDR | ||||||||||
| int | EXTLEN | ||||||||||
| long | EXTSIG | ||||||||||
| int | EXTSIZ | ||||||||||
| int | LOCCRC | ||||||||||
| int | LOCEXT | ||||||||||
| int | LOCFLG | ||||||||||
| int | LOCHDR | ||||||||||
| int | LOCHOW | ||||||||||
| int | LOCLEN | ||||||||||
| int | LOCNAM | ||||||||||
| long | LOCSIG | ||||||||||
| int | LOCSIZ | ||||||||||
| int | LOCTIM | ||||||||||
| int | LOCVER | ||||||||||
| [Expand] 
           Inherited Fields
           | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
|  From class java.util.zip.InflaterInputStream | |||||||||||
|  From class java.io.FilterInputStream | |||||||||||
| Public Constructors | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
|  | 
           Constructs a new 
            ZipInputStreamfrom the specified input stream. | ||||||||||
| Public Methods | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
|  | 
           Returns 0 when when this stream has exhausted its input; and 1 otherwise.
           | ||||||||||
|  | 
           Closes this 
            ZipInputStream. | ||||||||||
|  | 
           Closes the current ZIP entry and positions to read the next entry.
           | ||||||||||
|  | 
           Reads the next entry from this 
            ZipInputStreamornullif no more entries are present. | ||||||||||
|  | 
           Reads up to the specified number of uncompressed bytes into the buffer starting at the offset.
           | ||||||||||
| Protected Methods | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
|  | 
           creates a 
            ZipEntrywith the given name. | ||||||||||
| [Expand] 
           Inherited Methods
           | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
|  From class java.util.zip.InflaterInputStream | |||||||||||
|  From class java.io.FilterInputStream | |||||||||||
|  From class java.io.InputStream | |||||||||||
|  From class java.lang.Object | |||||||||||
|  From interface java.io.Closeable | |||||||||||
Constructs a new ZipInputStream from the specified input stream.
| stream | the input stream to representing a ZIP archive. | 
|---|
Returns 0 when when this stream has exhausted its input; and 1 otherwise. A result of 1 does not guarantee that further bytes can be returned, with or without blocking.
Although consistent with the RI, this behavior is inconsistent with available(), and violates the Liskov Substitution Principle. This method should not be used.
| IOException | 
|---|
Closes this ZipInputStream.
| IOException | if an IOExceptionoccurs. | 
|---|
Closes the current ZIP entry and positions to read the next entry.
| IOException | if an IOExceptionoccurs. | 
|---|
Reads the next entry from this ZipInputStream or null if no more entries are present.
ZipEntry contained in the input stream.| IOException | if an IOExceptionoccurs. | 
|---|
Reads up to the specified number of uncompressed bytes into the buffer starting at the offset.
| buffer | the byte array in which to store the bytes read. | 
|---|---|
| offset | the initial position in bufferto store the bytes read from this stream. | 
| byteCount | the maximum number of bytes to store in buffer. | 
| IOException | 
|---|
creates a ZipEntry with the given name.
| name | the name of the entry. | 
|---|
ZipEntry.