public class CSVFile extends javax.swing.filechooser.FileFilter implements CSVFileConstants
CSV (Comma Separated Values) file format parser. A CSV file is a spreadsheet, where the rows are separated by new line characters (i.e. each line of the file is a row), and the columns are separated by comma characters. Thus an example of a CSV file would be:
Name,Phone Num,Birthday John,555-5123,Apr. 30, 1937 Jane,555-4352,Feb. 13, 1976 Sam,555-6333,Jan. 7, 1961 Tom,555-7777,Aug. 4, 1943
Where name, phone number, and birthday are all separated by comma characters and are each columns of a spreadsheet.
NOTE: fields may be double or single quoted. In such cases, the single or double quotes character may be escaped by doubling it (e.g. "AB""C" will be read as AB"C).
Modifier and Type | Field and Description |
---|---|
static java.lang.String[][] |
DBL_EST
An empty 2D string array for calling the List.toArray method.
|
static java.lang.String[] |
EST
An empty 1D string array for calling the List.toArray method.
|
Token |
jj_nt
Next token.
|
Token |
token
Current token.
|
CSVFileTokenManager |
token_source
Generated Token Manager.
|
Constructor and Description |
---|
CSVFile()
Creates a new instance of CSVFile
|
CSVFile(CSVFileTokenManager tm)
Constructor with generated Token Manager.
|
CSVFile(java.io.InputStream stream)
Constructor with InputStream.
|
CSVFile(java.io.InputStream stream,
java.lang.String encoding)
Constructor with InputStream and supplied encoding
|
CSVFile(java.io.Reader stream)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
boolean |
accept(java.io.File file)
Determines whether a file is a CSV file (based on extension).
|
void |
disable_tracing()
Disable tracing.
|
void |
enable_tracing()
Enable tracing.
|
ParseException |
generateParseException()
Generate ParseException.
|
java.lang.String |
getDescription()
Returns a description of the file format that can be displayed to the
user.
|
Token |
getNextToken()
Get the next Token.
|
Token |
getToken(int index)
Get the specific Token.
|
boolean |
isFormat(java.io.Reader test)
Used to auto-detect BioLegato table canvas formats.
|
java.lang.String |
parseColumn()
Parses a column of the CSV data.
|
void |
parseCSV(TableCanvas table)
Parse CSV data into a table canvas.
|
java.lang.String[][] |
parseDoubleArray()
Parse CSV data into a table canvas.
|
java.lang.String[] |
parseRow()
Parses a row of the CSV data.
|
static java.lang.String[][] |
readCSV(java.io.Reader currentFile)
Reads CSV data from a Reader object into a 2D string array.
|
static void |
readFile(TableCanvas table,
java.io.Reader currentFile,
boolean overwrite,
boolean forceall)
Reads CSV data from a Reader object into a table canvas.
|
void |
ReInit(CSVFileTokenManager tm)
Reinitialise.
|
void |
ReInit(java.io.InputStream stream)
Reinitialise.
|
void |
ReInit(java.io.InputStream stream,
java.lang.String encoding)
Reinitialise.
|
void |
ReInit(java.io.Reader stream)
Reinitialise.
|
static void |
writeFile(java.lang.Appendable writer,
java.lang.String[][] data)
Writes a 2D string array as CSV data into an Appendable object.
|
public static final java.lang.String[] EST
public static final java.lang.String[][] DBL_EST
public CSVFileTokenManager token_source
public Token token
public Token jj_nt
public CSVFile()
public CSVFile(java.io.InputStream stream)
public CSVFile(java.io.InputStream stream, java.lang.String encoding)
public CSVFile(java.io.Reader stream)
public CSVFile(CSVFileTokenManager tm)
public boolean accept(java.io.File file)
accept
in class javax.swing.filechooser.FileFilter
file
- the file to test for CSV format compatibility.FileFilter.accept(java.io.File)
public java.lang.String getDescription()
getDescription
in class javax.swing.filechooser.FileFilter
FileFilter.getDescription()
public boolean isFormat(java.io.Reader test)
test
- the reader to attempt to detect the format of.public static void readFile(TableCanvas table, java.io.Reader currentFile, boolean overwrite, boolean forceall) throws java.io.IOException
table
- the table canvas to read the CSV file into.currentFile
- the Reader object to parsed the CSV data from.overwrite
- whether to overwrite the currently selected content
in the table canvas with the data parsed by this
function. Note that this currently does not work,
and should be implemented in the future.java.io.IOException
- thrown if there is any exception while
reading from the Reader object.public static java.lang.String[][] readCSV(java.io.Reader currentFile) throws java.io.IOException
currentFile
- the Reader object to parsed the CSV data from.java.io.IOException
- thrown if there is any exception while
reading from the Reader object.public static void writeFile(java.lang.Appendable writer, java.lang.String[][] data) throws java.io.IOException
writer
- the Appendable object to write the CSV data to.data
- the 2D string array to parse into CSV data.java.io.IOException
- thrown if there is any exception while
writing to the Appendable object.public final void parseCSV(TableCanvas table) throws ParseException
table
- the table canvas to parse the data into.ParseException
TableCanvas.namedHeaders
public final java.lang.String[][] parseDoubleArray() throws ParseException
ParseException
public final java.lang.String[] parseRow() throws ParseException
ParseException
public final java.lang.String parseColumn() throws ParseException
ParseException
public void ReInit(java.io.InputStream stream)
public void ReInit(java.io.InputStream stream, java.lang.String encoding)
public void ReInit(java.io.Reader stream)
public void ReInit(CSVFileTokenManager tm)
public final Token getNextToken()
public final Token getToken(int index)
public ParseException generateParseException()
public final void enable_tracing()
public final void disable_tracing()
Copyright © 2008-2022 University of Manitoba.