|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--bill.util.csv.CSVParser
Controls the reading of a CSV file. A CSV file is a comma delimited text data file.
Field Summary | |
protected Vector |
_csvLines
The list of lines read from the CSV file |
protected String |
_fileName
Name of the CSV file we are working with |
protected CSVLineParser |
_header
The first line of a csv file is a header line that lists what all the columns in the subsequent lines represent. |
protected boolean |
_modified
Indicates if the CSV has ben modified since it was read or last saved. |
protected Reader |
_reader
Allows an already opened CSV file |
protected int |
_skipLines
Number of lines to skip before 'really' reading the file. |
protected OutputStream |
_writer
A stream for writing out the CSV data |
Constructor Summary | |
CSVParser(OutputStream writer)
Alternate constructor for skipping lines. |
|
CSVParser(Reader reader)
Main constructor. |
|
CSVParser(Reader reader,
int skipLines)
Alternate constructor for skipping lines. |
|
CSVParser(Reader reader,
OutputStream writer)
Alternate constructor. |
|
CSVParser(Reader reader,
OutputStream writer,
int skipLines)
Alternate constructor for skipping lines. |
|
CSVParser(ResultSet resultSet)
Constructor for creating a CSV parser using a SQL result set. |
|
CSVParser(String fileName)
Main constructor. |
|
CSVParser(String fileName,
int skipLines)
Alternate constructor for skipping lines. |
Method Summary | |
void |
addLine(CSVLineParser line)
Appends the specified line to the current list of lines. |
void |
addLine(CSVLineParser line,
int lineNum)
Inserts the specified line at the specified index. |
String |
getFileName()
Retrieves the name of the file the CSV information is written to (and possibly read from). |
CSVLineParser |
getHeader()
Retrieves the header line for this CSV file. |
CSVLineParser |
getLine(int lineNum)
Return a specific data line's contents. |
String |
getLineLinePart(int lineNum,
int partNum)
Retrieves a specific line part from the specified line. |
String |
getLineLinePart(int lineNum,
String partName)
Retrieves a specific line part from the specified line. |
Vector |
getLines()
Retrieves the list of CSV lines for this parser. |
int |
getNumberOfLines()
Retrieves the number of lines read from the CSV file. |
int |
getPartNumber(String partName)
Determines the index of a specific line part name. |
boolean |
hasHeader()
Test for the presence of a header for this CSV file. |
boolean |
isModified()
Checks if the contents of the parser have been modified since they were read or last saved (whichever is more recent). |
static void |
main(String[] argv)
|
void |
removeLine(int lineNum)
Deletes the line at the specified index. |
void |
save()
Writes the CSV data out to a file. |
void |
setFileName(String fileName)
Set the name of the file the CSV information is written to (and possibly read from). |
void |
setLineLinePart(int lineNum,
int partNum,
String value)
Sets the specified line part from the specified line. |
void |
setLineLinePart(int lineNum,
String partName,
String value)
Sets the specified line part from the specified line. |
void |
setModified(boolean modified)
Sets the modified flag. |
void |
swapLines(int first,
int second)
Swaps the positions of the specified lines. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected int _skipLines
protected String _fileName
protected OutputStream _writer
protected Reader _reader
protected Vector _csvLines
protected CSVLineParser _header
protected boolean _modified
Constructor Detail |
public CSVParser(String fileName) throws CSVException
fileName
- The name of the CSV input file.CSVException
- If the input file cannot be found, opened, or
processed.public CSVParser(Reader reader) throws CSVException
save
method may not be used unless the setFileName
method is first
called. This is because we cannot determine a file name from just the
stream.reader
- The CSV input stream.CSVException
- If the input file cannot be found, opened, or
processed.save()
,
setFileName(String)
public CSVParser(String fileName, int skipLines) throws CSVException
fileName
- The name of the CSV input file.skipLines
- Number of lines to skip before 'really' reading the file.
This is to get past any lines that may be before the header.CSVException
- If the input file cannot be found, opened, or
processed.public CSVParser(Reader reader, int skipLines) throws CSVException
save
method may not be used unless the setFileName
method is first called. This is because we cannot determine a
file name from just the stream.reader
- The CSV input stream.skipLines
- Number of lines to skip before 'really' reading the file.
This is to get past any lines that may be before the header.CSVException
- If the input file cannot be found, opened, or
processed.save()
,
setFileName(String)
public CSVParser(Reader reader, OutputStream writer) throws CSVException
reader
- The CSV input stream.writer
- The output stream to write to when saving.CSVException
- If the input file cannot be found, opened, or
processed.public CSVParser(Reader reader, OutputStream writer, int skipLines) throws CSVException
reader
- The CSV input stream.writer
- The output stream to write to when saving.skipLines
- Number of lines to skip before 'really' reading the file.
This is to get past any lines that may be before the header.CSVException
- If the input file cannot be found, opened, or
processed.public CSVParser(OutputStream writer)
writer
- The output stream to write to when saving.public CSVParser(ResultSet resultSet) throws CSVException
save
method may not be used unless the setFileName
method is
first called. This is because we currently only support saving to a file
and we cannot determine a file name from a result set.resultSet
- The SQL result set to use in building the CSV
information.CSVException
- Thrown when the result set cannot be processed due
to a SQLException being thrown.save()
,
setFileName(String)
Method Detail |
public Vector getLines()
public boolean isModified()
true
if the parser's contents have been
modified, otherwise returns false
.public void setModified(boolean modified)
modified
- Value to set the modified flag to.public void save() throws Exception
Exception
- Thrown when the save file could not be opened or a
file name is not defined.public String getFileName()
public void setFileName(String fileName)
fileName
- The name of the CSV file.public CSVLineParser getLine(int lineNum)
lineNum
- The data line to retrieve. Uses a 0 based counter, so
the first data line is considered line 0.public String getLineLinePart(int lineNum, int partNum)
lineNum
- The data line to retrieve line part from. Uses a 0 based
counter, so the first data line is considered line 0.partNum
- The index of the part to be retrieved, this is a 0
(zero) based value, so 0 = first part.public String getLineLinePart(int lineNum, String partName) throws CSVException
lineNum
- The data line to retrieve line part from. Uses a 0 based
counter, so the first data line is considered line 0.partName
- The name of the part to be retrieved, based on the part
names read from the header line.CSVException
- Thrown when the part name is not valid.public void setLineLinePart(int lineNum, int partNum, String value)
lineNum
- The data line to retrieve line part from. Uses a 0 based
counter, so the first data line is considered line 0.partName
- The name of the part to be retrieved, based on the part
names read from the header line.public void setLineLinePart(int lineNum, String partName, String value) throws CSVException
lineNum
- The data line to retrieve line part from. Uses a 0 based
counter, so the first data line is considered line 0.partName
- The name of the part to be retrieved, based on the part
names read from the header line.CSVException
- Thrown when the part name is not valid.public int getPartNumber(String partName) throws CSVException
partName
- The name of the part to be retrieved, based on the part
names read from the header line.CSVException
- Thrown when the part name is not valid.public void addLine(CSVLineParser line)
line
- The line parser information to add.public void addLine(CSVLineParser line, int lineNum)
line
- The line parser information to add.lineNum
- The index to insert the new line at.public void removeLine(int lineNum)
lineNum
- The index of the line to remove.public int getNumberOfLines()
public CSVLineParser getHeader()
public boolean hasHeader()
true
if a header is setpublic void swapLines(int first, int second)
first
- The line number (0 based) of the first line to swap.second
- The line number (0 based) of the second line to swap.public static void main(String[] argv)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |