Class GavoCSVTableParser
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.
- Author:
- Gerard Lemson, Hans-Martin Adorf, Gerard Lemson, Mark Taylor
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
Recursive descent parser for parsing a single line -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionGavoCSVTableParser
(uk.ac.starlink.table.StoragePolicy storage, Component parent) Creates a new instance of CSVTableParserGavoCSVTableParser
(uk.ac.starlink.table.StoragePolicy storage, Component parent, String delimiter) Creates a new instance of CSVTableParser -
Method Summary
Modifier and TypeMethodDescriptionstatic Class
<?> classForJDBCType
(int jdbcType) Getter for property commentPrefix.Gets the delimiter.static Object
objectForJDBCType
(int jdbcType, String value) uk.ac.starlink.table.StarTable
parse
(InputStream stream) Return a List of tokens (Strings) from the specified line, delimited by the specified delimiter.void
setDelimiter
(String delimiter) Sets the delimiter to use.
-
Field Details
-
DEFAULT_DELIMITER
The default delimiter between table entries- See Also:
-
DEFAULT_COMMENT_PREFIX
The default comment prefix- See Also:
-
-
Constructor Details
-
GavoCSVTableParser
Creates a new instance of CSVTableParser -
GavoCSVTableParser
public GavoCSVTableParser(uk.ac.starlink.table.StoragePolicy storage, Component parent, String delimiter) Creates a new instance of CSVTableParser- Parameters:
parent
- component controlling this parser (may be null)delimiter
- the character delimiter ('separator')
-
-
Method Details
-
getCommentPrefix
Getter for property commentPrefix.- Returns:
- Value of property commentPrefix.
-
setDelimiter
Sets the delimiter to use.- Parameters:
delimiter
- the delimiter.
-
getDelimiter
Gets the delimiter.- Returns:
- a String with the delimiter.
-
parseLine
Return a List of tokens (Strings) from the specified line, delimited by the specified delimiter.- Parameters:
line
- a String with the line to parse- Returns:
- a List with the tokens
-
parse
- Throws:
Exception
-
classForJDBCType
-
objectForJDBCType
-