Java.Util.Zip.ZipInputStream Class
Used to read (decompress) the data from zip files.

See Also: ZipInputStream Members

Syntax

[Android.Runtime.Register("java/util/zip/ZipInputStream", DoNotGenerateAcw=true)]
public class ZipInputStream : InflaterInputStream

Remarks

Used to read (decompress) the data from zip files.

A zip file (or "archive") is a collection of (possibly) compressed files. When reading from a ZipInputStream, you call ZipInputStream.NextEntry which returns a Java.Util.Zip.ZipEntry of metadata corresponding to the userdata that follows. When you appear to have hit the end of this stream (which is really just the end of the current entry's userdata), call getNextEntry again. When it returns null, there are no more entries in the input file.

Although InflaterInputStream can only read compressed zip entries, this class can read non-compressed entries as well.

Use Java.Util.Zip.ZipFile if you need random access to entries by name, but use this class if you just want to iterate over all entries.

Example

Using ZipInputStream is a little more complicated than Java.Util.Zip.GZIPInputStream because zip files are containers that can contain multiple files. This code pulls all the files out of a zip file, similar to the unzip(1) utility.

java Example

 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();
 }
 

[Android Documentation]

Requirements

Namespace: Java.Util.Zip
Assembly: Mono.Android (in Mono.Android.dll)
Assembly Versions: 0.0.0.0
Since: Added in API level 1