|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.knowgate.misc.CSVParser
public class CSVParser
Delimited Text Parser
Parses a delimited text file into a memory array
| Constructor Summary | |
|---|---|
CSVParser()
|
|
CSVParser(java.lang.String sCharSetName)
Create CSV Parser and set encoding to be used |
|
| Method Summary | |
|---|---|
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 |
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 |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public CSVParser()
public CSVParser(java.lang.String sCharSetName)
sCharSetName - Name of charset encoding| Method Detail |
|---|
public 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 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 null
java.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 null
java.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 null
java.lang.IllegalArgumentException - if sFileDescriptor is ""
java.io.UnsupportedEncodingExceptionpublic int getColumnPosition(java.lang.String sColumnName)
sColumnName - Column Name
public 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') character
iLine - 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 instances
iLine - 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 Index
java.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 sensitive
iCol - int Column index [0..getColumnCount()-1]sVal - String Value sought
java.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 insensitive
iCol - int Column index [0..getColumnCount()-1]sVal - String Value sought
java.io.UnsupportedEncodingException
public void writeToStream(java.io.OutputStream oStrm)
throws java.io.IOException
oStrm - OutputStream
java.io.IOException
public void writeToFile(java.lang.String sFilePath)
throws java.io.IOException,
java.lang.SecurityException
oStrm - OutputStream
java.io.IOException
java.lang.SecurityException
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||