ewe.zip
Class ZipFile

java.lang.Object
  extended byewe.util.Errorable
      extended byewe.zip.ZipFile
All Implemented Interfaces:
Comparer, ZipConstants

public class ZipFile
extends Errorable
implements ZipConstants, Comparer

This class represents a Zip archive. You can ask for the contained entries, or get an input stream for a file entry. The entry is automatically decompressed. This class is thread safe: You can open input streams for arbitrary entries in different threads.


Field Summary
protected  RandomAccessStream raf
           
 ZipEntry root
           
 String zipName
           
 
Fields inherited from class ewe.util.Errorable
error
 
Fields inherited from interface ewe.zip.ZipConstants
C_COMPRESSED_SIZE, C_COMPRESSION_METHOD, C_CRC32, C_DISK_NUMBER_START, C_EXTERNAL_FILE_ATTRIBUTES, C_EXTRA_FIELD_LENGTH, C_FILE_COMMENT_LENGTH, C_FILENAME_LENGTH, C_GENERAL_PURPOSE_BIT_FLAG, C_HDR_SIG, C_INTERNAL_FILE_ATTRIBUTES, C_LAST_MOD_FILE_DATE, C_LAST_MOD_FILE_TIME, C_RELATIVE_OFFSET_LOCAL_HEADER, C_SIGNATURE, C_SIZE, C_UNCOMPRESSED_SIZE, C_VERSION_MADE_BY, C_VERSION_NEEDED_TO_EXTRACT, D_COMPRESSED_SIZE, D_CRC32, D_HDR_SIG, D_SIGNATURE, D_SIZE, D_UNCOMPRESSED_SIZE, EC_HDR_SIG, EC_NUM_DISK_WITH_START_CENTRAL_DIR, EC_NUM_ENTRIES_CENTRL_DIR_THS_DISK, EC_NUMBER_THIS_DISK, EC_OFFSET_START_CENTRAL_DIRECTORY, EC_SIGNATURE, EC_SIZE, EC_SIZE_CENTRAL_DIRECTORY, EC_TOTAL_ENTRIES_CENTRAL_DIR, EC_ZIPFILE_COMMENT_LENGTH, L_COMPRESSED_SIZE, L_COMPRESSION_METHOD, L_CRC32, L_EXTRA_FIELD_LENGTH, L_FILENAME_LENGTH, L_GENERAL_PURPOSE_BIT_FLAG, L_HDR_SIG, L_LAST_MOD_FILE_DATE, L_LAST_MOD_FILE_TIME, L_SIGNATURE, L_SIZE, L_UNCOMPRESSED_SIZE, L_VERSION_NEEDED_TO_EXTRACT, Z_BEST_COMPRESSION, Z_BEST_SPEED, Z_DEFAULT_COMPRESSION, Z_NO_COMPRESSION
 
Constructor Summary
ZipFile(File file)
          Opens a Zip file with the given name for reading.
ZipFile(RandomAccessStream stream)
          Opens a Zip file from the RandomAccessStream.
ZipFile(RandomAccessStream stream, Handle h)
          This should only be called from a Coroutine if the handle is not null.
ZipFile(String name)
          Opens a Zip file reading the given File.
 
Method Summary
 boolean close()
          Closes the ZipFile.
 int compare(Object one, Object two)
          This should compare the two objects and return: 0 = the objects are equal.
 Iterator entries()
          Returns an iterator of all Zip entries in this Zip file.
 ZipEntry getEntry(int which)
           
 ZipEntry getEntry(String name)
          Searches for a zip entry in this archive with the given name.
 Stream getInputStream(ZipEntry entry)
          Creates an input stream reading the given zip entry as uncompressed data.
 String getName()
          Returns the name of this zip file.
 boolean isOpen()
          Call this after creating the ZipFile to ensure that it was opened properly.
 int size()
          Returns the number of entries in this zip file.
 
Methods inherited from class ewe.util.Errorable
returnError, returnError, returnError
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, toString
 

Field Detail

raf

protected RandomAccessStream raf

zipName

public String zipName

root

public ZipEntry root
Constructor Detail

ZipFile

public ZipFile(RandomAccessStream stream)
Opens a Zip file from the RandomAccessStream.


ZipFile

public ZipFile(File file)
        throws IOException
Opens a Zip file with the given name for reading.

Throws:
IOException - if a i/o error occured.
ZipException - if the file doesn't contain a valid zip archive.

ZipFile

public ZipFile(String name)
        throws IOException
Opens a Zip file reading the given File.

Throws:
IOException - if a i/o error occured.
ZipException - if the file doesn't contain a valid zip archive.

ZipFile

public ZipFile(RandomAccessStream stream,
               Handle h)
This should only be called from a Coroutine if the handle is not null. It does not return until the zip file is fully opened unless the stop() method is called on the handle.

Method Detail

compare

public int compare(Object one,
                   Object two)
Description copied from interface: Comparer
This should compare the two objects and return: 0 = the objects are equal. greater than 0 = one is greater than two. less than 0 = two is greater than one.

Specified by:
compare in interface Comparer

isOpen

public boolean isOpen()
Call this after creating the ZipFile to ensure that it was opened properly.


close

public boolean close()
Closes the ZipFile. This also closes all input streams given by this class. After this is called, no further method should be called.

Throws:
IOException - if a i/o error occured.

entries

public Iterator entries()
Returns an iterator of all Zip entries in this Zip file.


getEntry

public ZipEntry getEntry(String name)
Searches for a zip entry in this archive with the given name.

Returns:
the zip entry, or null if no entry with that name exists.
See Also:
entries()

getInputStream

public Stream getInputStream(ZipEntry entry)
Creates an input stream reading the given zip entry as uncompressed data. Normally zip entry should be an entry returned by getEntry() or entries().

Returns:
the input stream or null on error.

getName

public String getName()
Returns the name of this zip file.


size

public int size()
Returns the number of entries in this zip file.


getEntry

public ZipEntry getEntry(int which)