org.melati.poem.csv
Class CSVFileParser

Package class diagram package CSVFileParser
java.lang.Object
  extended by org.melati.poem.csv.CSVFileParser

public class CSVFileParser
extends Object

A utility for tokenising a file made up of comma-separated variables. We allow for fields having returns in them.

   foo, bar om,,"baz, ,oof",xyz,   ->
     "foo", " bar om", "", "baz, , oof", "xyz", ""

   foo, "bar
   bar
   bar", baz ->
   "foo", "barbarbar", "baz"
 
Each record (which is usually a line, unless some fields have a line break in them) is accessed one at a time by calling nextRecord(). Within each record recordHasMoreFields() and nextField() can be used like an Enumeration to iterate through the fields.

Author:
mylesc, based heavily on orginal CSVStringEnumeration williamc

Constructor Summary
CSVFileParser(BufferedReader reader)
          Constructor.
 
Method Summary
 int getLineNo()
          Return the line number.
static void main(String[] args)
          Test harness.
 String nextField()
           
 boolean nextRecord()
           
 boolean recordHasMoreFields()
          Are there any more tokens to come?
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CSVFileParser

public CSVFileParser(BufferedReader reader)
Constructor.

Parameters:
reader - file reader
Method Detail

nextRecord

public boolean nextRecord()
                   throws IOException
Returns:
whether there is another line
Throws:
IOException

getLineNo

public int getLineNo()
Return the line number.

Returns:
the current lineNo

recordHasMoreFields

public boolean recordHasMoreFields()
Are there any more tokens to come?

Returns:
whether there are more fields

nextField

public String nextField()
                 throws IOException
Returns:
the next token as a String
Throws:
IOException

main

public static void main(String[] args)
                 throws Exception
Test harness.

Parameters:
args - arguments
Throws:
Exception - if anything fails


Copyright © 2000-2010 PanEris. All Rights Reserved.