Package org.apache.fulcrum.parser
Class DataStreamParser
java.lang.Object
org.apache.fulcrum.parser.DataStreamParser
- All Implemented Interfaces:
- Iterator<ValueParser>,- org.apache.avalon.framework.logger.LogEnabled
public abstract class DataStreamParser
extends Object
implements Iterator<ValueParser>, org.apache.avalon.framework.logger.LogEnabled
DataStreamParser is used to parse a stream with a fixed format and
 generate ValueParser objects which can be used to extract the values
 in the desired type.
 
The class itself is abstract - a concrete subclass which implements the initTokenizer method such as CSVParser or TSVParser is required to use the functionality.
The class implements the java.util.Iterator interface for convenience. This allows simple use in a Velocity template for example:
#foreach ($row in $datastream) Name: $row.Name Description: $row.Description #end
- Version:
- $Id$
- Author:
- Sean Legassick
- 
Field SummaryFieldsModifier and TypeFieldDescriptionprotected org.apache.avalon.framework.logger.LoggerLogger to use
- 
Constructor SummaryConstructorsConstructorDescriptionDataStreamParser(Reader in, List<String> columnNames, String characterEncoding) Create a new DataStreamParser instance.
- 
Method SummaryModifier and TypeMethodDescriptionvoidenableLogging(org.apache.avalon.framework.logger.Logger logger) Provide a loggerbooleanhasNext()Determine whether a further row of values exists in the input.booleanDetermine whether a further row of values exists in the input.protected abstract voidinitTokenizer(StreamTokenizer tokenizer) Initialize the StreamTokenizer instance used to read the lines from the input reader.next()Returns a ValueParser object containing the next row of values.nextRow()Returns a ValueParser object containing the next row of values.voidRead the list of column names from the input reader using the tokenizer.voidremove()The optional Iterator.remove method is not supported.voidsetColumnNames(List<String> columnNames) Set the list of column names explicitly.Methods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.util.IteratorforEachRemaining
- 
Field Details- 
logprotected org.apache.avalon.framework.logger.Logger logLogger to use
 
- 
- 
Constructor Details- 
DataStreamParserCreate a new DataStreamParser instance. Requires a Reader to read the comma-separated values from, a list of column names and a character encoding.- Parameters:
- in- the input reader.
- columnNames- a list of column names.
- characterEncoding- the character encoding of the input.
 
 
- 
- 
Method Details- 
initTokenizerInitialize the StreamTokenizer instance used to read the lines from the input reader. This must be implemented in subclasses to set up the tokenizing properties.- Parameters:
- tokenizer- the StreamTokenizer to use
 
- 
enableLoggingpublic void enableLogging(org.apache.avalon.framework.logger.Logger logger) Provide a logger- Specified by:
- enableLoggingin interface- org.apache.avalon.framework.logger.LogEnabled
- See Also:
 
- 
setColumnNamesSet the list of column names explicitly.- Parameters:
- columnNames- A list of column names.
 
- 
readColumnNamesRead the list of column names from the input reader using the tokenizer.- Throws:
- IOException- an IOException occurred.
 
- 
hasNextRowDetermine whether a further row of values exists in the input.- Returns:
- true if the input has more rows.
- Throws:
- IOException- an IOException occurred.
 
- 
nextRowReturns a ValueParser object containing the next row of values.- Returns:
- a ValueParser object.
- Throws:
- IOException- an IOException occurred.
- NoSuchElementException- there are no more rows in the input.
 
- 
hasNextpublic boolean hasNext()Determine whether a further row of values exists in the input.- Specified by:
- hasNextin interface- Iterator<ValueParser>
- Returns:
- true if the input has more rows.
 
- 
nextReturns a ValueParser object containing the next row of values.- Specified by:
- nextin interface- Iterator<ValueParser>
- Returns:
- a ValueParser object as an Object.
- Throws:
- NoSuchElementException- there are no more rows in the input or an IOException occurred.
 
- 
removeThe optional Iterator.remove method is not supported.- Specified by:
- removein interface- Iterator<ValueParser>
- Throws:
- UnsupportedOperationException- the operation is not supported.
 
 
-