com.pmease.quickbuild.plugin.report.engine.util.csv
Class CSVParser

java.lang.Object
  extended by com.pmease.quickbuild.plugin.report.engine.util.csv.CSVParser

public class CSVParser
extends java.lang.Object

Parses CSV lines of text. Options are available to choose the

Notes: Line with trailing comma will result in an empty string field

Attempts to follow this suggestion from RFC4180: Implementors should "be conservative in what you do, be liberal in what you accept from others" (RFC 793) when processing CSV files.

Since:
1.0
See Also:
Comma Separated Values on Wikipedia, RFC 4180

Constructor Summary
CSVParser()
          Constructor with default delimiter (,) and trimFields (true).
CSVParser(char delimiter)
           
CSVParser(char delimiter, boolean trimFields)
          Constructs the parser with specified options
 
Method Summary
 java.lang.String[] parse(java.lang.String line)
           
 java.util.List<java.lang.String> tokenize(java.lang.String line)
          Assumes this is one line of CSV text
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CSVParser

public CSVParser()
Constructor with default delimiter (,) and trimFields (true).


CSVParser

public CSVParser(char delimiter)

CSVParser

public CSVParser(char delimiter,
                 boolean trimFields)
Constructs the parser with specified options

Parameters:
delimiter - field separator character (e.g. comma, tab, vertical bar / pipe, space)
trimFields - indicates if fields are to be trimmed or not
Method Detail

parse

public java.lang.String[] parse(java.lang.String line)
                         throws ParseException
Throws:
ParseException

tokenize

public java.util.List<java.lang.String> tokenize(java.lang.String line)
                                          throws ParseException
Assumes this is one line of CSV text

Parameters:
line - line of text to parse
Returns:
list of tokens/fields; never returns null
Throws:
ParseException - if
  1. carriage return/newline found outside of a double quote, and
  2. terminating double quote not found


Copyright © 2005-2010 PMEase Inc. All Rights Reserved.