org.apache.commons.compress.archivers.zip
Class ZipArchiveInputStream

java.lang.Object
  extended by java.io.InputStream
      extended by org.apache.commons.compress.archivers.ArchiveInputStream
          extended by org.apache.commons.compress.archivers.zip.ZipArchiveInputStream
All Implemented Interfaces:
Closeable
Direct Known Subclasses:
JarArchiveInputStream

public class ZipArchiveInputStream
extends ArchiveInputStream

Implements an input stream that can read Zip archives.

Note that ZipEntry.getSize() may return -1 if the DEFLATE algorithm is used, as the size information is not available from the header.

The ZipFile class is preferred when reading from files.

See Also:
ZipFile
This class is not thread-safe

Constructor Summary
ZipArchiveInputStream(InputStream inputStream)
           
ZipArchiveInputStream(InputStream inputStream, String encoding, boolean useUnicodeExtraFields)
           
ZipArchiveInputStream(InputStream inputStream, String encoding, boolean useUnicodeExtraFields, boolean allowStoredEntriesWithDataDescriptor)
           
 
Method Summary
 boolean canReadEntryData(ArchiveEntry ae)
          Whether this class is able to read the given entry.
 void close()
           
 ArchiveEntry getNextEntry()
          Returns the next Archive Entry in this Stream.
 ZipArchiveEntry getNextZipEntry()
           
static boolean matches(byte[] signature, int length)
          Checks if the signature matches what is expected for a zip file.
 int read(byte[] buffer, int start, int length)
           
 long skip(long value)
           
 
Methods inherited from class org.apache.commons.compress.archivers.ArchiveInputStream
count, count, getBytesRead, getCount, pushedBackBytes, read
 
Methods inherited from class java.io.InputStream
available, mark, markSupported, read, reset
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ZipArchiveInputStream

public ZipArchiveInputStream(InputStream inputStream)

ZipArchiveInputStream

public ZipArchiveInputStream(InputStream inputStream,
                             String encoding,
                             boolean useUnicodeExtraFields)
Parameters:
encoding - the encoding to use for file names, use null for the platform's default encoding
useUnicodeExtraFields - whether to use InfoZIP Unicode Extra Fields (if present) to set the file names.

ZipArchiveInputStream

public ZipArchiveInputStream(InputStream inputStream,
                             String encoding,
                             boolean useUnicodeExtraFields,
                             boolean allowStoredEntriesWithDataDescriptor)
Parameters:
encoding - the encoding to use for file names, use null for the platform's default encoding
useUnicodeExtraFields - whether to use InfoZIP Unicode Extra Fields (if present) to set the file names.
allowStoredEntriesWithDataDescriptor - whether the stream will try to read STORED entries that use a data descriptor
Since:
Apache Commons Compress 1.1
Method Detail

getNextZipEntry

public ZipArchiveEntry getNextZipEntry()
                                throws IOException
Throws:
IOException

getNextEntry

public ArchiveEntry getNextEntry()
                          throws IOException
Returns the next Archive Entry in this Stream.

Specified by:
getNextEntry in class ArchiveInputStream
Returns:
the next entry, or null if there are no more entries
Throws:
IOException - if the next entry could not be read

canReadEntryData

public boolean canReadEntryData(ArchiveEntry ae)
Whether this class is able to read the given entry.

May return false if it is set up to use encryption or a compression method that hasn't been implemented yet.

Overrides:
canReadEntryData in class ArchiveInputStream
Since:
Apache Commons Compress 1.1

read

public int read(byte[] buffer,
                int start,
                int length)
         throws IOException
Overrides:
read in class InputStream
Throws:
IOException

close

public void close()
           throws IOException
Specified by:
close in interface Closeable
Overrides:
close in class InputStream
Throws:
IOException

skip

public long skip(long value)
          throws IOException
Overrides:
skip in class InputStream
Throws:
IOException

matches

public static boolean matches(byte[] signature,
                              int length)
Checks if the signature matches what is expected for a zip file. Does not currently handle self-extracting zips which may have arbitrary leading content.

Parameters:
signature - the bytes to check
length - the number of bytes to check
Returns:
true, if this stream is a zip archive stream, false otherwise


Copyright © 2010 The Apache Software Foundation. All Rights Reserved.