tribble.search.zip
Class ZFile

java.lang.Object
  extended bytribble.search.zip.ZFile
All Implemented Interfaces:
DocumentI

public class ZFile
extends java.lang.Object
implements DocumentI

Zipfile data file.

This represents the contents of an entry found within a zipfile.

Since:
2001-05-18
Version:
$Revision: 1.6 $ $Date: 2001/07/02 22:40:58 $
Author:
David R. Tribble (david@tribble.com).
Copyright 2001 by David R. Tribble, all rights reserved.
See Also:
ZArchive

Field Summary
protected  java.util.zip.ZipEntry m_entry
           
protected  ZArchive m_searcher
          Searcher that found and created this zipfile entry.
protected  int m_serialNo
          Serial number (zipfile open count).
protected static java.lang.String[] s_attrNames
          Zipfile entry key attribute names.
static int SERIES
          Series number.
 
Constructor Summary
protected ZFile(ZArchive searcher, java.util.zip.ZipEntry ent, int serialNo)
          Constructor.
 
Method Summary
 boolean canRead()
          Determine if this zipfile entry is readable.
 boolean canWrite()
          Determine if this zipfile entry is writable.
 boolean exists()
          Determine if this zipfile entry exists.
 java.lang.Object getAttribute(java.lang.String key)
          Retrieve the value of an attribute for this zipfile entry.
 java.lang.String[] getAttributeNames()
          Retrieve the attribute names for this zipfile entry.
 java.io.InputStream getInputStream()
          Get a readable input stream for this zipfile entry.
 java.lang.String getName()
          Retrieve the name of this zipfile entry.
 java.lang.String getType()
          Retrieve the type of the data file corresponding to this zipfile entry.
 boolean isDirectory()
          Determine if this zipfile entry specifies a directory entry.
 java.util.Date lastModified()
          Determine the date that this zipfile entry was last modified.
 long length()
          Determine the length of this zipfile entry.
 void setAttribute(java.lang.String attr, java.lang.Object val)
          Set the value of an attribute for this zipfile entry.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SERIES

public static final int SERIES
Series number.

See Also:
Constant Field Values

s_attrNames

protected static final java.lang.String[] s_attrNames
Zipfile entry key attribute names.


m_searcher

protected ZArchive m_searcher
Searcher that found and created this zipfile entry.


m_entry

protected java.util.zip.ZipEntry m_entry

m_serialNo

protected int m_serialNo
Serial number (zipfile open count). This is used to determine if the zipfile has been closed or reopened since this entry was created, and thus whether this entry is still valid or not.

Constructor Detail

ZFile

protected ZFile(ZArchive searcher,
                java.util.zip.ZipEntry ent,
                int serialNo)
Constructor.

Parameters:
searcher - The zipfile searcher that found and created this entry.
ent - The zipfile entry for this file entry.
serialNo - The open count at the time the zipfile containing this entry was opened.
Since:
1.3, 2001-06-15
Method Detail

exists

public boolean exists()
Determine if this zipfile entry exists.

Specified by:
exists in interface DocumentI
Returns:
True always.
Since:
1.3, 2001-06-15

isDirectory

public boolean isDirectory()
Determine if this zipfile entry specifies a directory entry.

Specified by:
isDirectory in interface DocumentI
Returns:
True if this entry names a directory, otherwise false.
Since:
1.3, 2001-06-15

canRead

public boolean canRead()
Determine if this zipfile entry is readable.

Specified by:
canRead in interface DocumentI
Returns:
True always.
Since:
1.3, 2001-06-15
See Also:
DocumentI.getInputStream(), DocumentI.canWrite()

canWrite

public boolean canWrite()
Determine if this zipfile entry is writable.

Specified by:
canWrite in interface DocumentI
Returns:
False always (since zipfile entries cannot be written to).
Since:
1.3, 2001-06-15
See Also:
DocumentI.getInputStream(), DocumentI.canRead()

length

public long length()
Determine the length of this zipfile entry.

Specified by:
length in interface DocumentI
Returns:
The size of this file, in bytes.
Since:
1.3, 2001-06-15

lastModified

public java.util.Date lastModified()
Determine the date that this zipfile entry was last modified.

Specified by:
lastModified in interface DocumentI
Returns:
The date that this file was last modified, or null if the date is unknown.
Since:
1.3, 2001-06-15

getName

public java.lang.String getName()
Retrieve the name of this zipfile entry.

Specified by:
getName in interface DocumentI
Returns:
The name of this file.
Since:
1.3, 2001-06-15

getType

public java.lang.String getType()
Retrieve the type of the data file corresponding to this zipfile entry.

Specified by:
getType in interface DocumentI
Returns:
The type of the file (which is the filename extension or suffix, which can be empty ""). Such a type name is typically suitable for display by some user interface.
Since:
1.3, 2001-06-15

getAttributeNames

public java.lang.String[] getAttributeNames()
Retrieve the attribute names for this zipfile entry.

Specified by:
getAttributeNames in interface DocumentI
Returns:
An array containing the names of the attributes associated with this zipfile entry, or null if it has none.
Throws:
java.lang.Exception - Thrown if the information about the entry is unobtainable, or if some other error occurs.
Since:
1.5, 2001-06-30
See Also:
getAttribute(java.lang.String)

getAttribute

public java.lang.Object getAttribute(java.lang.String key)
Retrieve the value of an attribute for this zipfile entry.

Specified by:
getAttribute in interface DocumentI
Parameters:
key - The name of an attribute associated with this zipfile entry. The following attribute names are supported:
    "comment"           String
    "compressed_size"   Long
    "crc"               Long
    "extra"             byte[]
    "method"            String
    "name"              String
    "size"              Long
    "time"              Date 
Returns:
The value of the specified attribute, or null if this entry has no such attribute. Note that the value is returned as a generic Object, meaning that it must be cast into the appropriate type.
Throws:
java.lang.Exception - Thrown if the information about the entry is unobtainable, or if some other error occurs.
Since:
1.5, 2001-06-30
See Also:
getAttributeNames()

setAttribute

public void setAttribute(java.lang.String attr,
                         java.lang.Object val)
                  throws java.lang.Exception,
                         java.lang.UnsupportedOperationException
Set the value of an attribute for this zipfile entry. This method is not supported.

Specified by:
setAttribute in interface DocumentI
Parameters:
attr - The name of an attribute associated with this document.
val - The new value of the specified attribute.
Throws:
java.lang.UnsupportedOperationException - (unchecked) Always thrown, because this method is not implemented for this document type.
java.lang.Exception - Thrown if the information about the document cannot be set, or if some other error occurs.
Since:
1.5, 2001-06-30
See Also:
DocumentI.getAttributeNames()

getInputStream

public java.io.InputStream getInputStream()
                                   throws java.io.IOException,
                                          java.util.zip.ZipException
Get a readable input stream for this zipfile entry.

Specified by:
getInputStream in interface DocumentI
Returns:
An input stream, from which the data contents of this zipfile entry can be read.
Throws:
java.io.IOException - Thrown if the input stream cannot be obtained, or if some other error occurs.
java.util.zip.ZipException - Thrown if the input stream cannot be obtained from the zipfile.
Since:
1.1, 2001-05-18