uk.ac.starlink.datanode.nodes
Class ZipArchiveDataNode

java.lang.Object
  extended by uk.ac.starlink.datanode.nodes.DefaultDataNode
      extended by uk.ac.starlink.datanode.nodes.ZipArchiveDataNode
All Implemented Interfaces:
DataNode
Direct Known Subclasses:
ZipFileDataNode, ZipStreamDataNode

public abstract class ZipArchiveDataNode
extends DefaultDataNode

DataNode representing a Zip archive. This abstract class embodies the common functionality required by its subclasses ZipFileDataNode and ZipStreamDataNode.

Author:
Mark Taylor (Starlink)

Constructor Summary
protected ZipArchiveDataNode(DataSource datsrc)
          Constructs a ZipArchiveDataNode.
 
Method Summary
 boolean allowsChildren()
          The DefaultDataNode implementation of this method returns false.
 Iterator getChildIterator()
          The DefaultDataNode implementation of this method throws UnsupportedOperationException (DefaultDataNode.allowsChildren() is false).
protected abstract  Iterator getChildIteratorAtLevel(String level, DataNode parent)
          Returns an iterator over the DataNodes at a given level in the hierarchy of this archive.
protected abstract  List getEntries()
          Returns a list of all the ZipEntry objects in this zip archive.
protected  List getEntriesAtLevel(String level)
          Returns all the ZipEntry objects in this archive at a given level in the hierarchy.
 String getName()
          Gets the name of this object.
 String getNodeTLA()
          Returns the string "ZIP".
 String getNodeType()
          Returns a short sentence indicating what kind of node this is.
 String getPathSeparator()
          Returns a default separator string.
static boolean isMagic(byte[] magic)
          Tests whether the presented byte array looks like the start of a Zip archive.
 
Methods inherited from class uk.ac.starlink.datanode.nodes.DefaultDataNode
beep, configureDetail, getChildMaker, getCreator, getDataObject, getDescription, getIcon, getLabel, getParentObject, getPathElement, hasDataObject, makeChild, makeErrorChild, registerDataObject, setChildMaker, setCreator, setDescription, setIconID, setLabel, setName, setParentObject, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ZipArchiveDataNode

protected ZipArchiveDataNode(DataSource datsrc)
                      throws NoSuchDataException
Constructs a ZipArchiveDataNode.

Parameters:
datsrc - a data source corresponding to the archive; this is used for checking the magic number to see whether it looks like a zip archive or not
Throws:
NoSuchDataException
Method Detail

getEntries

protected abstract List getEntries()
                            throws IOException
Returns a list of all the ZipEntry objects in this zip archive.

Returns:
a List of all the ZipEntry objects which make up this zip archive.
Throws:
IOException

getChildIteratorAtLevel

protected abstract Iterator getChildIteratorAtLevel(String level,
                                                    DataNode parent)
                                             throws IOException
Returns an iterator over the DataNodes at a given level in the hierarchy of this archive. The iterator creates DataNodes for each ZipEntry in this archive whose name begins with the supplied string level.

Parameters:
level - the required starting substring of the name of all ZipEntries to be represented in the result
parent - the DataNode whose children the resulting nodes will be
Returns:
an Iterator over DataNode objects corresponding to the ZipEntry objects specified by level
Throws:
IOException

isMagic

public static boolean isMagic(byte[] magic)
Tests whether the presented byte array looks like the start of a Zip archive.

Parameters:
magic - a byte array containing the first few bytes of a source which might be a zip
Returns:
true iff magic represents the magic number of a zip archive

getName

public String getName()
Description copied from interface: DataNode
Gets the name of this object. This is an intrinsic property of the object.

Specified by:
getName in interface DataNode
Overrides:
getName in class DefaultDataNode
Returns:
the name of the object

getPathSeparator

public String getPathSeparator()
Description copied from class: DefaultDataNode
Returns a default separator string.

Specified by:
getPathSeparator in interface DataNode
Overrides:
getPathSeparator in class DefaultDataNode
Returns:
"."

getNodeTLA

public String getNodeTLA()
Returns the string "ZIP".

Specified by:
getNodeTLA in interface DataNode
Overrides:
getNodeTLA in class DefaultDataNode
Returns:
"ZIP"

getNodeType

public String getNodeType()
Description copied from interface: DataNode
Returns a short sentence indicating what kind of node this is. The return value should be just a few words. As a rough guideline it should indicate what the implementing class is.

Specified by:
getNodeType in interface DataNode
Overrides:
getNodeType in class DefaultDataNode
Returns:
a short description of the type of this DataNode

allowsChildren

public boolean allowsChildren()
Description copied from class: DefaultDataNode
The DefaultDataNode implementation of this method returns false.

Specified by:
allowsChildren in interface DataNode
Overrides:
allowsChildren in class DefaultDataNode
Returns:
true if the node is of a type which can have child nodes, false otherwise

getChildIterator

public Iterator getChildIterator()
Description copied from class: DefaultDataNode
The DefaultDataNode implementation of this method throws UnsupportedOperationException (DefaultDataNode.allowsChildren() is false).

Specified by:
getChildIterator in interface DataNode
Overrides:
getChildIterator in class DefaultDataNode
Returns:
an Iterator over the children. Each object iterated over should be a DataNode. Behaviour is undefined if this method is called on an object for which allowsChildren returns false.

getEntriesAtLevel

protected List getEntriesAtLevel(String level)
                          throws IOException
Returns all the ZipEntry objects in this archive at a given level in the hierarchy. The selected entries are all those whose name starts with the supplied string level.

Parameters:
level - the required starting substring of the name of all ZipEntries to be returned
Returns:
a list of all the ZipEntry objects at the given level
Throws:
IOException


Copyright © 2015 Central Laboratory of the Research Councils. All Rights Reserved.