CubeTwister 2.0alpha142 2012-02-11

ch.randelshofer.io
Class CSVReader

java.lang.Object
  extended by ch.randelshofer.io.CSVReader

public class CSVReader
extends java.lang.Object

Reads values from a comma separated (CSV) stream.

EBNF rules for the CSV format:

 CSV = Record {RecordSeparator, Record}
 
 Record = Field {FieldSeparator, Field}
 RecordSeparator = linebreak
 
 Field = UnquotedField | DQuotedField
 FieldSeparator = {whitespace} comma {whitespace}
 
 UnquotedField = (simplechar) {{simplechar|space}, (simplechar)}
 
 DQuotedField = dquote (simplechar|stuffeddquote|linebreak|comma} dquote
 
 
 simplechar = (* every character except specialchar *)
 specialchar = linebreak | comma | dquote | whitespace
 linebreak = lf | cr | cr, lf
 comma = ','
 dquote = '"'
 stuffeddquote = '""'
 lf = 0x0a
 cr = 0x0d
 whitespace = space | tab
 space = ' '
 tab = 0x07
 
 

Simple Example with unquoted fields:

 Jacques, Mayol, Rue St. Claire 8, Antibes
 Enzo, Maiorca, Via Roma 2, Taormina
 
Example with quoted fields:
 Trio, "Uno, due, tre!", Pop
 Alice, "Did you go?
 Did you stay?", Rock
 The Pringles, "He said ""I like it""", Pop
 

Version:
1.0.1 2011-10-13 New class comments.
1.0 2004-04-18 Created.
Author:
Werner Randelshofer

Constructor Summary
CSVReader(java.io.Reader in, char delimiterChar, char quoteChar)
          Creates a new instance.
 
Method Summary
 void close()
           
 java.lang.String[] readln()
          Returns null, if EOF has been reached.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CSVReader

public CSVReader(java.io.Reader in,
                 char delimiterChar,
                 char quoteChar)
Creates a new instance.

Method Detail

readln

public java.lang.String[] readln()
                          throws java.io.IOException
Returns null, if EOF has been reached.

Throws:
java.io.IOException

close

public void close()
           throws java.io.IOException
Throws:
java.io.IOException

(c) Werner Randelshofer.
All rights reserved.