Klasse CSVParser

Alle implementierten Schnittstellen:
Iterator<ValueParser>, org.apache.avalon.framework.logger.LogEnabled

public class CSVParser extends DataStreamParser
CSVParser is used to parse a stream with comma-separated values and generate ParameterParser objects which can be used to extract the values in the desired type.

The class extends the abstract class DataStreamParser and implements initTokenizer with suitable values for CSV files to provide this functionality.

The class (indirectly through DataStreamParser) implements the java.util.Iterator interface for convenience. This allows simple use in a Velocity template for example:

 #foreach ($row in $csvfile)
   Name: $row.Name
   Description: $row.Description
 #end
 
Version:
$Id$
Autor:
Sean Legassick
  • Konstruktordetails

    • CSVParser

      public CSVParser(Reader in)
      Create a new CSVParser instance. Requires a Reader to read the comma-separated values from. The column headers must be set independently either explicitly, or by reading the first line of the CSV values.
      Parameter:
      in - the input reader.
    • CSVParser

      public CSVParser(Reader in, List<String> columnNames)
      Create a new CSVParser instance. Requires a Reader to read the comma-separated values from, and a list of column names.
      Parameter:
      in - the input reader.
      columnNames - a list of column names.
    • CSVParser

      public CSVParser(Reader in, List<String> columnNames, String characterEncoding)
      Create a new CSVParser instance. Requires a Reader to read the comma-separated values from, a list of column names and a character encoding.
      Parameter:
      in - the input reader.
      columnNames - a list of column names.
      characterEncoding - the character encoding of the input.
  • Methodendetails

    • initTokenizer

      protected void initTokenizer(StreamTokenizer tokenizer)
      Initialize the StreamTokenizer instance used to read the lines from the input reader.
      Angegeben von:
      initTokenizer in Klasse DataStreamParser
      Parameter:
      tokenizer - the StreamTokenizer to use