public class GavoCSVTableParser
extends java.lang.Object
We follow and expand on the specification for CSV files as detailed in http://www.edoceo.com/utilis/csv-file-format.php. We expand on this by allowing zero, one or more header lines. If header lines are there, we assume the last one to give the names of the columns. By default we assume 1 header line is available, the actual number may be set in the appropriate parseCSV method.
We do allow for delimiters different from a comma, but we treat their occurence exactly as otherwise the comma would be treated according to the specification.
We do NOT allow for string demarcations different from the double-quote.
A a final touch we allow for "comment" lines starting with a comment string. Lines starting with the comment string (e.g. ";;") will be ignored (but see next paragraph). This is needed in order to be able to successfully parse CSV files as output by CDS/Vizier, or the GAVO "simpledb" web applications.
Addition: we assume that there are comment lines starting with "#COLUMN" which indicate metadata about all the columns. We assume that the first line without "#" symbol contains the column names. All subsequent rows are data.
Modifier and Type | Class | Description |
---|---|---|
static class |
GavoCSVTableParser.RecursiveDescentParser |
Recursive descent parser for parsing a single line
|
Modifier and Type | Field | Description |
---|---|---|
static java.lang.String |
DEFAULT_COMMENT_PREFIX |
The default comment prefix
|
static java.lang.String |
DEFAULT_DELIMITER |
The default delimiter between table entries
|
Constructor | Description |
---|---|
GavoCSVTableParser(uk.ac.starlink.table.StoragePolicy storage,
java.awt.Component parent) |
Creates a new instance of CSVTableParser
|
GavoCSVTableParser(uk.ac.starlink.table.StoragePolicy storage,
java.awt.Component parent,
java.lang.String delimiter) |
Creates a new instance of CSVTableParser
|
Modifier and Type | Method | Description |
---|---|---|
static java.lang.Class |
classForJDBCType(int jdbcType) |
|
java.lang.String |
getCommentPrefix() |
Getter for property commentPrefix.
|
java.lang.String |
getDelimiter() |
Gets the delimiter.
|
static java.lang.Object |
objectForJDBCType(int jdbcType,
java.lang.String value) |
|
uk.ac.starlink.table.StarTable |
parse(java.io.InputStream stream) |
|
java.util.List |
parseLine(java.lang.String line) |
Return a List of tokens (Strings) from the specified line, delimited by
the specified delimiter.
|
void |
setDelimiter(java.lang.String delimiter) |
Sets the delimiter to use.
|
public static final java.lang.String DEFAULT_DELIMITER
public static final java.lang.String DEFAULT_COMMENT_PREFIX
public GavoCSVTableParser(uk.ac.starlink.table.StoragePolicy storage, java.awt.Component parent)
public GavoCSVTableParser(uk.ac.starlink.table.StoragePolicy storage, java.awt.Component parent, java.lang.String delimiter)
parent
- component controlling this parser (may be null)delimiter
- the character delimiter ('separator')public java.lang.String getCommentPrefix()
public void setDelimiter(java.lang.String delimiter)
delimiter
- the delimiter.public java.lang.String getDelimiter()
public java.util.List parseLine(java.lang.String line)
line
- a String with the line to parsepublic uk.ac.starlink.table.StarTable parse(java.io.InputStream stream) throws java.lang.Exception
java.lang.Exception
public static java.lang.Class classForJDBCType(int jdbcType)
public static java.lang.Object objectForJDBCType(int jdbcType, java.lang.String value)
Copyright © 2003-2018 CCLRC: Council for the Central Laboratory of the Research Councils. All Rights Reserved.