FreeHEP API
Version current

org.freehep.record.loop.examples
Class EchoStrings.LineSupplier

java.lang.Object
  extended byorg.freehep.record.loop.examples.EchoStrings.LineSupplier
All Implemented Interfaces:
SequentialRecordSource
Enclosing class:
EchoStrings

public class EchoStrings.LineSupplier
extends Object
implements SequentialRecordSource

Class to read in file line by line.

Source Code:
EchoStrings.LineSupplier.java

Field Summary
 
Fields inherited from interface org.freehep.record.source.SequentialRecordSource
UNKNOWN
 
Constructor Summary
EchoStrings.LineSupplier(String filename)
          Create an instance of this class that will read the specified file.
 
Method Summary
 void close()
          Close the record source and free any associated resources
 Object getCurrentRecord()
          Get the current record.
 long getEstimatedSize()
          Returns the number of records in this record source, if known.
 Class getRecordClass()
          Find out what type of records are returned by this record source.
 String getSourceName()
          Get the (human readable) name of this record source.
 void next()
          Go to the next record.
 void releaseRecord(Object record)
          Releases any resources associated with the specified record.
 void rewind()
          Repositions the record source before the first record.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EchoStrings.LineSupplier

public EchoStrings.LineSupplier(String filename)
                         throws FileNotFoundException
Create an instance of this class that will read the specified file.

Parameters:
filename - the name of the file to read.
Method Detail

getCurrentRecord

public Object getCurrentRecord()
                        throws EndOfSourceException,
                               IOException
Description copied from interface: SequentialRecordSource
Get the current record.

Specified by:
getCurrentRecord in interface SequentialRecordSource
Returns:
The current record, or null if no current record.
Throws:
EndOfSourceException
IOException

getEstimatedSize

public long getEstimatedSize()
Description copied from interface: SequentialRecordSource
Returns the number of records in this record source, if known.

This is allowed to be an approximation (for example the number of events may be known but not the total number of records, or the expected number of records may be known, but the actual number may be different). The primary use of this method is for giving the user feedback on how much of a record source has been read, it should not be used as the limit for a for loop. Use hasNext() instead.

Specified by:
getEstimatedSize in interface SequentialRecordSource
Returns:
The approximate number of records, or UNKNOWN.

next

public void next()
Description copied from interface: SequentialRecordSource
Go to the next record. Note that record sources are initially positioned before the first record, so next() must be called once before calling getCurrentRecord().

Specified by:
next in interface SequentialRecordSource

getRecordClass

public Class getRecordClass()
Description copied from interface: SequentialRecordSource
Find out what type of records are returned by this record source. All records returned are gauranteed to be of this type. This method should return Object.class if nothing more is known.

Specified by:
getRecordClass in interface SequentialRecordSource
Returns:
The class of records returned by this record source.

getSourceName

public String getSourceName()
Description copied from interface: SequentialRecordSource
Get the (human readable) name of this record source. This is typically the file name for RecordSources associated with files.

Specified by:
getSourceName in interface SequentialRecordSource
Returns:
The record source name.

rewind

public void rewind()
            throws IOException
Description copied from interface: SequentialRecordSource
Repositions the record source before the first record.

Specified by:
rewind in interface SequentialRecordSource
Throws:
IOException

releaseRecord

public void releaseRecord(Object record)
Description copied from interface: SequentialRecordSource
Releases any resources associated with the specified record.

Specified by:
releaseRecord in interface SequentialRecordSource

close

public void close()
           throws IOException
Description copied from interface: SequentialRecordSource
Close the record source and free any associated resources

Specified by:
close in interface SequentialRecordSource
Throws:
IOException

FreeHEP API
Version current

Copyright © 2000-2004 FreeHEP, All Rights Reserved.