thinkmap.datasource.flatfile2
Class CSVReader

java.lang.Object
  extended by thinkmap.datasource.flatfile2.CSVReader
All Implemented Interfaces:
Closeable, IFlatFileReader

public class CSVReader
extends Object
implements IFlatFileReader


Field Summary
static char DEFAULT_ESCAPE_CHARACTER
          The default escape character to use if none is supplied to the constructor.
static char DEFAULT_QUOTE_CHARACTER
          The default quote character to use if none is supplied to the constructor.
static char DEFAULT_SEPARATOR
          The default separator to use if none is supplied to the constructor.
static int DEFAULT_SKIP_LINES
          The default line to start reading.
static int INITIAL_READ_SIZE
           
 
Constructor Summary
CSVReader(thinkmap.datasource.flatfile2.IFFEntityModel model, URL url)
          Constructs CSVReader using a comma for the separator.
 
Method Summary
 void close()
          Closes the underlying reader.
 int getLineNumber()
          Returns the current line number
 long getModificationTime()
           
 List<String[]> readAll()
          Reads the entire file into a List with each element being a String[] of tokens.
 String[] readNext()
          Reads the next line from the buffer and converts to a string array.
protected  String stripBOMs(String line)
          So Apparently in UTF encodings, there are these hidden characters called Byte Order Marks (BOMS).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_SEPARATOR

public static final char DEFAULT_SEPARATOR
The default separator to use if none is supplied to the constructor.

See Also:
Constant Field Values

INITIAL_READ_SIZE

public static final int INITIAL_READ_SIZE
See Also:
Constant Field Values

DEFAULT_QUOTE_CHARACTER

public static final char DEFAULT_QUOTE_CHARACTER
The default quote character to use if none is supplied to the constructor.

See Also:
Constant Field Values

DEFAULT_ESCAPE_CHARACTER

public static final char DEFAULT_ESCAPE_CHARACTER
The default escape character to use if none is supplied to the constructor.

See Also:
Constant Field Values

DEFAULT_SKIP_LINES

public static final int DEFAULT_SKIP_LINES
The default line to start reading.

See Also:
Constant Field Values
Constructor Detail

CSVReader

public CSVReader(thinkmap.datasource.flatfile2.IFFEntityModel model,
                 URL url)
          throws IOException
Constructs CSVReader using a comma for the separator.

Parameters:
reader - the reader to an underlying CSV source.
Throws:
IOException
Method Detail

getModificationTime

public long getModificationTime()
Specified by:
getModificationTime in interface IFlatFileReader

readAll

public List<String[]> readAll()
                       throws IOException
Reads the entire file into a List with each element being a String[] of tokens.

Returns:
a List of String[], with each String[] representing a line of the file.
Throws:
IOException - if bad things happen during the read

readNext

public String[] readNext()
                  throws IOException
Reads the next line from the buffer and converts to a string array.

Specified by:
readNext in interface IFlatFileReader
Returns:
a string array with each comma-separated element as a separate entry.
Throws:
IOException - if bad things happen during the read

getLineNumber

public int getLineNumber()
Description copied from interface: IFlatFileReader
Returns the current line number

Specified by:
getLineNumber in interface IFlatFileReader
Returns:

close

public void close()
           throws IOException
Closes the underlying reader.

Specified by:
close in interface Closeable
Throws:
IOException - if the close fails

stripBOMs

protected String stripBOMs(String line)
So Apparently in UTF encodings, there are these hidden characters called Byte Order Marks (BOMS). Sadly, Java doesn't handle BOMS correctly (ignore them in input streams like everyone else) so this is a little work around that checks to see if they exist and if they do it removes them from the string. Essentially the buffer passed in is the first 4 characters of the line passed in. Based on the appropriate BOM, if present, the appropriate number of characters are removed from the String. The following chart below is for all UTF BOMS. 00 00 FE FF UTF-32, big-endian FF FE 00 00 UTF-32, little-endian FE FF UTF-16, big-endian FF FE UTF-16, little-endian EF BB BF UTF-8

Parameters:
buffer -
line -
Returns:
String


Copyright © 2013 Thinkmap, Inc. All Rights Reserved.