public abstract class DataStreamParser extends Object implements Iterator<ValueParser>, org.apache.avalon.framework.logger.LogEnabled
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
Modifier and Type | Field and Description |
---|---|
protected org.apache.avalon.framework.logger.Logger |
log
Logger to use
|
Constructor and Description |
---|
DataStreamParser(Reader in,
List<String> columnNames,
String characterEncoding)
Create a new DataStreamParser instance.
|
Modifier and Type | Method and Description |
---|---|
void |
enableLogging(org.apache.avalon.framework.logger.Logger logger)
Provide a logger
|
boolean |
hasNext()
Determine whether a further row of values exists in the input.
|
boolean |
hasNextRow()
Determine whether a further row of values exists in the input.
|
protected abstract void |
initTokenizer(StreamTokenizer tokenizer)
Initialize the StreamTokenizer instance used to read the lines
from the input reader.
|
ValueParser |
next()
Returns a ValueParser object containing the next row of values.
|
ValueParser |
nextRow()
Returns a ValueParser object containing the next row of values.
|
void |
readColumnNames()
Read the list of column names from the input reader using the
tokenizer.
|
void |
remove()
The optional Iterator.remove method is not supported.
|
void |
setColumnNames(List<String> columnNames)
Set the list of column names explicitly.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
forEachRemaining
public DataStreamParser(Reader in, List<String> columnNames, String characterEncoding)
in
- the input reader.columnNames
- a list of column names.characterEncoding
- the character encoding of the input.protected abstract void initTokenizer(StreamTokenizer tokenizer)
tokenizer
- the StreamTokenizer to usepublic void enableLogging(org.apache.avalon.framework.logger.Logger logger)
enableLogging
in interface org.apache.avalon.framework.logger.LogEnabled
LogEnabled.enableLogging(org.apache.avalon.framework.logger.Logger)
public void setColumnNames(List<String> columnNames)
columnNames
- A list of column names.public void readColumnNames() throws IOException
IOException
- an IOException occurred.public boolean hasNextRow() throws IOException
IOException
- an IOException occurred.public ValueParser nextRow() throws IOException, NoSuchElementException
IOException
- an IOException occurred.NoSuchElementException
- there are no more rows in the input.public boolean hasNext()
hasNext
in interface Iterator<ValueParser>
public ValueParser next() throws NoSuchElementException
next
in interface Iterator<ValueParser>
NoSuchElementException
- there are no more rows in the input
or an IOException occurred.public void remove() throws UnsupportedOperationException
remove
in interface Iterator<ValueParser>
UnsupportedOperationException
- the operation is not supported.Copyright © 2005–2019 The Apache Software Foundation. All rights reserved.