Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| ESC/Java2 © 2003,2004,2005 David Cok and Joseph Kiniry © 2005 UCD Dublin © 2003,2004 Radboud University Nijmegen © 1999,2000 Compaq Computer Corporation © 1997,1998,1999 Digital Equipment Corporation All Rights Reserved
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## javafe.filespace
Class ZipTree

    java.lang.Object
      javafe.filespace.Tree
          javafe.filespace.HashTree
              javafe.filespace.ExtTree
                  javafe.filespace.ZipTree

class ZipTree
extends ExtTree

A ZipTree is a Tree that mirrors the contents of a zipfile; the constructor takes in a pathname and returns a tree representing the filesystem contained in that zipfile.

ZipTree works by scanning the zipfile at object creation time, building up a hierarchical list of all the files in the zipfile. Later modifications to the zipfile will not be reflected in the ZipTree.

The data field of every (sub)node in a ZipTree contains a non-null ZipGenericFile representing the file it mirrors (or would mirror if a corresponding entry existed) in the underlying zipfile.

Note: ZipTree interior or root nodes (and only interior or root nodes) may contain ZipGenericFiles that do not have a corresponding zip entry because there may be no zip entries for those directories. E.g., the zipfile might contain a file for X/Y but not for X

We use "./" as the ZipGenericFile name to represent the missing root directory (no ZipTree actually has a root directory as far as we can tell). This gives the right isDirectory behavior (since it ends with a "/"), but the wrong local name ("."). This is the best we can do, though, since the other alternative ("") gives the reverse behavior, which is worse for us since we rely on the isDirectory bit and only use local names for non-directories.

Field Summary
`protected java.util.Hashtable` | `edges` The mapping between our outgoing edge's labels and the subTrees they point to.
`protected java.util.zip.ZipFile` | `zip` The zipfile we are a snapshot of

Fields inherited from class javafe.filespace.Tree
`data`

Constructor Summary
`ZipTree(java.io.File zipfile)` Create a ZipTree to mirror a zipfile's contents.

Method Summary
`ExtTree` | `addChild(java.lang.String label, java.lang.Object newData)` Create a new direct child of us with label label and data newData.
`ExtTree` | `addPath(java.lang.String[] path)` This is an extended version of addChild that takes a path (a list of labels) instead of a single label.
`private void` | `addZipEntry(java.util.zip.ZipEntry z)` Add a ZipEntry to this tree according to its pathname:
`java.util.Enumeration` | `children()` An enumeration of this node's direct children.
`Tree` | `getChild(java.lang.String label)` Fetch our direct child along the edge labelled label.
`private void` | `loadZipData()` Create a tree of ZipEntry's from the pathnames of the ZipEntry's in zip
`static void` | `main(java.lang.String[] args)` A simple test driver
`protected static void` | `missingEntry(Tree node, java.util.zip.ZipFile zip)` Initialize a node's data field to a ZipGenericFile that represents the file that it would correspond to if the tree it belongs to mirrored zip.

Methods inherited from class javafe.filespace.Tree
`getChildrenCount, getLabel, getParent, getQualifiedChild, getQualifiedName, getRootNode, getSimpleName, isLeaf, print, printDetails`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### zip

    protected java.util.zip.ZipFile zip

  The zipfile we are a snapshot of

### edges

    protected java.util.Hashtable edges

  The mapping between our outgoing edge's labels and the subTrees they point to. No entry for a label means no edge with that label exists.

  Invariant: all elements of edges are Trees and all keys are Strings.

Constructor Detail

### ZipTree

    public ZipTree(java.io.File zipfile)
            throws java.io.IOException,
                   java.util.zip.ZipException

  Create a ZipTree to mirror a zipfile's contents.

  May throw an IOException (e.g., file doesn't exist) or a ZipException (e.g., file is not a properly formatted zipfile).

Method Detail

### missingEntry

    protected static void missingEntry(Tree node,
                                       java.util.zip.ZipFile zip)

  Initialize a node's data field to a ZipGenericFile that represents the file that it would correspond to if the tree it belongs to mirrored zip.

### loadZipData

    private void loadZipData()

  Create a tree of ZipEntry's from the pathnames of the ZipEntry's in zip

### addZipEntry

    private void addZipEntry(java.util.zip.ZipEntry z)

  Add a ZipEntry to this tree according to its pathname:

### main

    public static void main(java.lang.String[] args)

  A simple test driver

### addChild

    public ExtTree addChild(java.lang.String label,
                            java.lang.Object newData)

  Create a new direct child of us with label label and data newData. The new child will have no direct children.

  If a child by the name of label already exists, then this routine leaves the tree unchanged.

  In either case, the (resulting) child with label label is returned.

### addPath

    public ExtTree addPath(java.lang.String[] path)

  This is an extended version of addChild that takes a path (a list of labels) instead of a single label. It returns the child located by following path from this node. It creates any necessary nodes along the way using addChild with null for newData. Path must be non-null.

### children

    public java.util.Enumeration children()

  An enumeration of this node's direct children. Each child occurs exactly once in the enumeration. The order is unspecified and may differ from call to call.

  Note: The Objects returned by the resulting enumeration's nextElement method are guaranteed to be of type Tree and non-null.

  Specified by:
    `children` in class `Tree`

### getChild

    public Tree getChild(java.lang.String label)

  Fetch our direct child along the edge labelled label. Iff there is no such child, return null.

  Overrides:
    `getChild` in class `Tree`

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| ESC/Java2 © 2003,2004,2005 David Cok and Joseph Kiniry © 2005 UCD Dublin © 2003,2004 Radboud University Nijmegen © 1999,2000 Compaq Computer Corporation © 1997,1998,1999 Digital Equipment Corporation All Rights Reserved
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

The ESC/Java2 Project Homepage