| |
|
| java.lang.Object org.apache.turbine.util.parser.DataStreamParser
All known Subclasses: org.apache.turbine.util.parser.TSVParser, org.apache.turbine.util.parser.CSVParser,
DataStreamParser | abstract public class DataStreamParser implements Iterator(Code) | | 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
author: Sean Legassick author: Martin van den Bemt author: Henning P. Schmiedehausen version: $Id: DataStreamParser.java 534527 2007-05-02 16:10:59Z tv $ |
Method Summary | |
public List | getColumnNames() get the list of column names. | public boolean | hasNext() Determine whether a further row of values exists in the input. | public boolean | hasNextRow() Determine whether a further row of values exists in the input. | protected void | initTokenizer(StreamTokenizer tokenizer) Initialize the StreamTokenizer instance used to read the lines
from the input reader. | public Object | next() Returns a ValueParser object containing the next row of values. | public ValueParser | nextRow() Returns a ValueParser object containing the next row of values. | public void | readColumnNames() Read the list of column names from the input reader using the
tokenizer. | public void | remove() The optional Iterator.remove method is not supported. | public void | setColumnNames(List columnNames) Set the list of column names explicitly. | public void | setFieldSeparator(char fieldSeparator) |
EMPTYFIELDNAME | final protected static String EMPTYFIELDNAME(Code) | | The constant for empty fields
|
DataStreamParser | public DataStreamParser(Reader in, List columnNames, String characterEncoding)(Code) | | Create 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. Parameters: columnNames - a list of column names. Parameters: characterEncoding - the character encoding of the input. |
getColumnNames | public List getColumnNames()(Code) | | get the list of column names.
|
hasNext | public boolean hasNext()(Code) | | Determine whether a further row of values exists in the input.
true if the input has more rows. |
hasNextRow | public boolean hasNextRow() throws IOException(Code) | | Determine whether a further row of values exists in the input.
true if the input has more rows. exception: IOException - an IOException occurred. |
initTokenizer | protected void initTokenizer(StreamTokenizer tokenizer)(Code) | | Initialize the StreamTokenizer instance used to read the lines
from the input reader. This must be implemented in subclasses to
set up other tokenizing properties.
Parameters: tokenizer - the tokenizer to adjust |
readColumnNames | public void readColumnNames() throws IOException(Code) | | Read the list of column names from the input reader using the
tokenizer. If fieldNames are empty, we use the current fieldNumber
+ the EMPTYFIELDNAME to make one up.
exception: IOException - an IOException occurred. |
setColumnNames | public void setColumnNames(List columnNames)(Code) | | Set the list of column names explicitly.
Parameters: columnNames - A list of column names. |
setFieldSeparator | public void setFieldSeparator(char fieldSeparator)(Code) | | This method must be called to setup the field seperator
Parameters: fieldSeparator - the char which separates the fields |
|
|
|