FreeHEP API
Version current

hep.graphics.heprep.ref
Class AbstractHepRepReader

java.lang.Object
  extended byhep.graphics.heprep.ref.AbstractHepRepReader
All Implemented Interfaces:
HepRepReader
Direct Known Subclasses:
DefaultHepRepReader, XMLHepRepReader

public abstract class AbstractHepRepReader
extends Object
implements HepRepReader

This abstract HepRep Reader handles ZipInputStreams, ZipFiles, reads the "heprep.properties" file, allows for properties to be quesried and handles files to be skipped while iterating. It assumes the concrete subclass has Sequential access. ZipFiles will provide Random access as well. The reset method should implement the opening of the file(s), or call super.reset(). Reset should be called from the constructor to open the initial file.

Version:
$Id: AbstractHepRepReader.java,v 1.7 2004/09/08 23:05:33 duns Exp $
Author:
M.Donszelmann
Source Code:
AbstractHepRepReader.java

Field Summary
static String cvsId
           
protected  InputStream input
           
protected  String name
           
protected  ZipFile zipFile
           
 
Constructor Summary
protected AbstractHepRepReader(InputStream in)
           
protected AbstractHepRepReader(String fileName)
           
 
Method Summary
 void close()
          Closes the reader and its underlying stream.
 String entryName()
          Returns the current entry name (random acces only).
 List entryNames()
          Returns a list of names of available entries (random rccess only).
 String getProperty(String key, String defaultValue)
          Returns a property (if set in the heprep.properties file).
 boolean hasNext()
          Is there a next heprep.
 boolean hasRandomAccess()
          Allows random access.
 boolean hasSequentialAccess()
          Allows for sequential access.
 HepRep next()
          Reads the next HepRep from the Reader.
 HepRep read(String name)
          Reads a HepRep by name (random access only).
protected abstract  HepRep readHepRep(InputStream input)
           
 void reset()
          Resets a sequential HepRep reader.
 int size()
          Returns the (estimated) number of HepReps in the reader.
 int skip(int n)
          Skips a number of HepReps in the reader.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

cvsId

public static final String cvsId
See Also:
Constant Field Values

input

protected InputStream input

name

protected String name

zipFile

protected ZipFile zipFile
Constructor Detail

AbstractHepRepReader

protected AbstractHepRepReader(InputStream in)
                        throws IOException

AbstractHepRepReader

protected AbstractHepRepReader(String fileName)
                        throws IOException
Method Detail

getProperty

public String getProperty(String key,
                          String defaultValue)
                   throws IOException
Description copied from interface: HepRepReader
Returns a property (if set in the heprep.properties file).

Specified by:
getProperty in interface HepRepReader
Parameters:
key - property name
defaultValue - value if property not found
Throws:
IOException - in case of a stream problem.

close

public void close()
           throws IOException
Description copied from interface: HepRepReader
Closes the reader and its underlying stream.

Specified by:
close in interface HepRepReader
Throws:
IOException - in case of a stream problem.

hasSequentialAccess

public boolean hasSequentialAccess()
                            throws IOException
Description copied from interface: HepRepReader
Allows for sequential access.

Specified by:
hasSequentialAccess in interface HepRepReader
Returns:
true if sequential access is possible.
Throws:
IOException - in case of a stream problem.

reset

public void reset()
           throws IOException,
                  UnsupportedOperationException
Description copied from interface: HepRepReader
Resets a sequential HepRep reader.

Specified by:
reset in interface HepRepReader
Throws:
UnsupportedOperationException - if the reader does not support sequential access.
IOException - in case of a stream problem.

size

public int size()
Description copied from interface: HepRepReader
Returns the (estimated) number of HepReps in the reader. Zip files may contain instructions to skip a number of files. These files will not be included in the estimate.

Specified by:
size in interface HepRepReader
Returns:
number of HepReps, or -1 if cannot be calculated.

skip

public int skip(int n)
         throws UnsupportedOperationException
Description copied from interface: HepRepReader
Skips a number of HepReps in the reader. Zip files may contain instructions to skip a number of files. These files will not be included in the count to be skipped.

Specified by:
skip in interface HepRepReader
Parameters:
n - number of HepReps to be skipped.
Returns:
number of HepReps skipped.
Throws:
UnsupportedOperationException - if the reader does not support sequential access.

hasNext

public boolean hasNext()
                throws IOException,
                       UnsupportedOperationException
Description copied from interface: HepRepReader
Is there a next heprep.

Specified by:
hasNext in interface HepRepReader
Returns:
true if the next heprep is available.
Throws:
IOException - in case of a stream problem.
UnsupportedOperationException - if the reader does not support sequential access.

next

public HepRep next()
            throws IOException,
                   UnsupportedOperationException,
                   NoSuchElementException
Description copied from interface: HepRepReader
Reads the next HepRep from the Reader.

Specified by:
next in interface HepRepReader
Returns:
heprep.
Throws:
NoSuchElementException - if the heprep is not available, or EOF.
UnsupportedOperationException - if the reader does not support sequential access.
IOException - in case of a stream problem.

hasRandomAccess

public boolean hasRandomAccess()
Description copied from interface: HepRepReader
Allows random access.

Specified by:
hasRandomAccess in interface HepRepReader
Returns:
true if this reader provides random access

read

public HepRep read(String name)
            throws IOException,
                   UnsupportedOperationException,
                   NoSuchElementException
Description copied from interface: HepRepReader
Reads a HepRep by name (random access only).

Specified by:
read in interface HepRepReader
Parameters:
name - for the heprep to be read.
Returns:
heprep.
Throws:
IOException - in case of a stream problem.
UnsupportedOperationException - if the reader does not support random access.
NoSuchElementException - if the heprep is not available.

entryName

public String entryName()
Description copied from interface: HepRepReader
Returns the current entry name (random acces only).

Specified by:
entryName in interface HepRepReader
Returns:
name of the current entry or null if not supported.

entryNames

public List entryNames()
Description copied from interface: HepRepReader
Returns a list of names of available entries (random rccess only). Zip files may contain instructions to skip a number of files. These files will not be included in the entries.

Specified by:
entryNames in interface HepRepReader
Returns:
list of entrynames or null if not supported.

readHepRep

protected abstract HepRep readHepRep(InputStream input)
                              throws IOException
Throws:
IOException

FreeHEP API
Version current

Copyright © 2000-2004 FreeHEP, All Rights Reserved.