public class CSVParser
extends java.lang.Object
Delimited Text Parser
Parses a delimited text file into a memory array
Constructor and Description |
---|
CSVParser() |
CSVParser(java.lang.String sCharSetName)
Create CSV Parser and set encoding to be used
|
Modifier and Type | Method and Description |
---|---|
java.lang.String |
charSet() |
void |
charSet(java.lang.String sCharSetName) |
int |
errorLine() |
int |
find(int iCol,
java.lang.String sVal)
Find first occurence of a value at a given column
Search is case sensitive
|
int |
findi(int iCol,
java.lang.String sVal)
Find first occurence of a value at a given column
Search is case insensitive
|
int |
getColumnCount()
Get column count
|
int |
getColumnPosition(java.lang.String sColumnName) |
char |
getDelimiter() |
java.lang.String |
getField(int iCol,
int iRow)
Get value for a field at a given row and column.
|
java.lang.String |
getField(java.lang.String sCol,
int iRow)
Get value for a field at a given row and column.
|
java.lang.String |
getLine(int iLine)
Get line from a parsed file.
|
java.util.HashMap |
getLineAsMap(int iLine)
Get line from a parsed file as a Map of named values.
|
int |
getLineCount()
Get line count
|
void |
parseData(char[] aCharData,
java.lang.String sFileDescriptor)
Parse data from a character array
Parsed values are stored at an internal array in this CSVParser.
|
void |
parseFile(java.io.File oFile,
java.lang.String sFileDescriptor)
Parse a delimited text file
Parsed values are stored at an internal array in this CSVParser.
|
void |
parseFile(java.lang.String sFilePath,
java.lang.String sFileDescriptor)
Parse a delimited text file
Parsed values are stored at an internal array in this CSVParser.
|
void |
parseSheet(org.apache.poi.hssf.usermodel.HSSFSheet oSheet,
java.lang.String sFileDescriptor) |
void |
writeToFile(java.lang.String sFilePath)
Write CSVParser matrix to delimited text file
|
void |
writeToStream(java.io.OutputStream oStrm)
Write CSVParser matrix to an output stream
|
public CSVParser()
public CSVParser(java.lang.String sCharSetName)
sCharSetName
- Name of charset encodingpublic java.lang.String charSet()
public void charSet(java.lang.String sCharSetName)
public int getLineCount()
public int getColumnCount()
public int errorLine()
public char getDelimiter()
public void parseSheet(org.apache.poi.hssf.usermodel.HSSFSheet oSheet, java.lang.String sFileDescriptor)
public void parseData(char[] aCharData, java.lang.String sFileDescriptor) throws java.lang.ArrayIndexOutOfBoundsException, java.lang.RuntimeException, java.lang.NullPointerException, java.lang.IllegalArgumentException
Parse data from a character array
Parsed values are stored at an internal array in this CSVParser.sFileDescriptor
- A list of column names separated by ',' ';' '|' '`' or '\t'.
Column names may be quoted. Lines are delimiter by '\n' charactersjava.lang.ArrayIndexOutOfBoundsException
- Delimited values for a file is greater
than columns specified at descriptor.java.lang.RuntimeException
- If delimiter is not one of { ',' ';' '|' '`' or '\t' }java.lang.NullPointerException
- if sFileDescriptor is nulljava.lang.IllegalArgumentException
- if sFileDescriptor is ""public void parseFile(java.io.File oFile, java.lang.String sFileDescriptor) throws java.lang.ArrayIndexOutOfBoundsException, java.io.IOException, java.io.FileNotFoundException, java.lang.RuntimeException, java.lang.NullPointerException, java.lang.IllegalArgumentException, java.io.UnsupportedEncodingException
Parse a delimited text file
Parsed values are stored at an internal array in this CSVParser.oFile
- CSV FilesFileDescriptor
- A list of column names separated by ',' ';' '|' '`' or '\t'.
Column names may be quoted. Lines are delimiter by '\n' charactersjava.io.IOException
java.io.FileNotFoundException
java.lang.ArrayIndexOutOfBoundsException
- Delimited values for a file is greater
than columns specified at descriptor.java.lang.RuntimeException
- If delimiter is not one of { ',' ';' '|' '`' or '\t' }java.lang.NullPointerException
- if oFile or sFileDescriptor are nulljava.lang.IllegalArgumentException
- if sFileDescriptor is ""java.io.UnsupportedEncodingException
public void parseFile(java.lang.String sFilePath, java.lang.String sFileDescriptor) throws java.lang.ArrayIndexOutOfBoundsException, java.io.IOException, java.io.FileNotFoundException, java.lang.RuntimeException, java.lang.NullPointerException, java.lang.IllegalArgumentException, java.io.UnsupportedEncodingException
Parse a delimited text file
Parsed values are stored at an internal array in this CSVParser.sFilePath
- File PathsFileDescriptor
- A list of column names separated by ',' ';' '|' '`' or '\t'.
Column names may be quoted. Lines are delimiter by '\n' charactersjava.io.IOException
java.io.FileNotFoundException
java.lang.ArrayIndexOutOfBoundsException
- Delimited values for a file is greater
than columns specified at descriptor.java.lang.RuntimeException
- If delimiter is not one of { ',' ';' '|' '`' or '\t' }java.lang.NullPointerException
- if oFile or sFileDescriptor are nulljava.lang.IllegalArgumentException
- if sFileDescriptor is ""java.io.UnsupportedEncodingException
public int getColumnPosition(java.lang.String sColumnName)
sColumnName
- Column Namepublic java.lang.String getLine(int iLine) throws java.lang.IllegalStateException, java.io.UnsupportedEncodingException
Get line from a parsed file.
Lines are delimited by the Line Feed (LF, CHAR(10), '\n') characteriLine
- Line Number [0..getLineCount()-1]java.lang.IllegalStateException
- If parseFile() has not been called prior to getLine()java.io.UnsupportedEncodingException
public java.util.HashMap getLineAsMap(int iLine) throws java.lang.IllegalStateException, java.io.UnsupportedEncodingException, java.lang.ArrayIndexOutOfBoundsException
Get line from a parsed file as a Map of named values.
This method is usefull when parsing plain text lines into DBPersist instancesiLine
- Line Number [0..getLineCount()-1]java.lang.IllegalStateException
- If parseFile() has not been called prior to getLine()java.io.UnsupportedEncodingException
java.lang.ArrayIndexOutOfBoundsException
public java.lang.String getField(int iCol, int iRow) throws java.lang.IllegalStateException, java.lang.ArrayIndexOutOfBoundsException, java.lang.StringIndexOutOfBoundsException, java.io.UnsupportedEncodingException
Get value for a field at a given row and column.
Column indexes are zero based.iCol
- Column IndexiRow
- Row Indexjava.lang.IllegalStateException
- If parseFile() method was not called prior to
getField()java.lang.ArrayIndexOutOfBoundsException
- If Column or Row Index is out of bounds.java.lang.StringIndexOutOfBoundsException
- If Row is malformed.java.io.UnsupportedEncodingException
- If charset encoding name is not recognized.public java.lang.String getField(java.lang.String sCol, int iRow) throws java.lang.IllegalStateException, java.lang.ArrayIndexOutOfBoundsException, java.lang.StringIndexOutOfBoundsException, java.io.UnsupportedEncodingException
Get value for a field at a given row and column.
sCol
- Column nameiRow
- Row position [0..getLineCount()-1]java.lang.IllegalStateException
java.lang.ArrayIndexOutOfBoundsException
java.lang.StringIndexOutOfBoundsException
java.io.UnsupportedEncodingException
public int find(int iCol, java.lang.String sVal) throws java.io.UnsupportedEncodingException
Find first occurence of a value at a given column
Search is case sensitiveiCol
- int Column index [0..getColumnCount()-1]sVal
- String Value soughtjava.io.UnsupportedEncodingException
public int findi(int iCol, java.lang.String sVal) throws java.io.UnsupportedEncodingException
Find first occurence of a value at a given column
Search is case insensitiveiCol
- int Column index [0..getColumnCount()-1]sVal
- String Value soughtjava.io.UnsupportedEncodingException
public void writeToStream(java.io.OutputStream oStrm) throws java.io.IOException
oStrm
- OutputStreamjava.io.IOException
public void writeToFile(java.lang.String sFilePath) throws java.io.IOException, java.lang.SecurityException
oStrm
- OutputStreamjava.io.IOException
java.lang.SecurityException