public class GavoCSVTableParser extends 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 and Description |
---|---|
static class |
GavoCSVTableParser.RecursiveDescentParser
Recursive descent parser for parsing a single line
|
Modifier and Type | Field and Description |
---|---|
static String |
DEFAULT_COMMENT_PREFIX
The default comment prefix
|
static String |
DEFAULT_DELIMITER
The default delimiter between table entries
|
Constructor and Description |
---|
GavoCSVTableParser(uk.ac.starlink.table.StoragePolicy storage,
Component parent)
Creates a new instance of CSVTableParser
|
GavoCSVTableParser(uk.ac.starlink.table.StoragePolicy storage,
Component parent,
String delimiter)
Creates a new instance of CSVTableParser
|
Modifier and Type | Method and Description |
---|---|
static Class<?> |
classForJDBCType(int jdbcType) |
String |
getCommentPrefix()
Getter for property commentPrefix.
|
String |
getDelimiter()
Gets the delimiter.
|
static Object |
objectForJDBCType(int jdbcType,
String value) |
uk.ac.starlink.table.StarTable |
parse(InputStream stream) |
List<String> |
parseLine(String line)
Return a List of tokens (Strings) from the specified line, delimited by
the specified delimiter.
|
void |
setDelimiter(String delimiter)
Sets the delimiter to use.
|
public static final String DEFAULT_DELIMITER
public static final String DEFAULT_COMMENT_PREFIX
public GavoCSVTableParser(uk.ac.starlink.table.StoragePolicy storage, Component parent)
public String getCommentPrefix()
public void setDelimiter(String delimiter)
delimiter
- the delimiter.public String getDelimiter()
public List<String> parseLine(String line)
line
- a String with the line to parsepublic uk.ac.starlink.table.StarTable parse(InputStream stream) throws Exception
Exception
public static Class<?> classForJDBCType(int jdbcType)
Copyright © 2003-2025 CCLRC: Council for the Central Laboratory of the Research Councils. All Rights Reserved.