uk.ac.starlink.topcat.contrib.gavo
Class GavoCSVTableParser

java.lang.Object
  extended by uk.ac.starlink.topcat.contrib.gavo.GavoCSVTableParser

public class GavoCSVTableParser
extends Object

Class for a parser that can parse CSV input streams, such as those produced by GAVO's database query web apps.

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
static class GavoCSVTableParser.RecursiveDescentParser
          Recursive descent parser for parsing a single line
 
Field Summary
static String DEFAULT_COMMENT_PREFIX
          The default comment prefix
static String DEFAULT_DELIMITER
          The default delimiter between table entries
 
Constructor Summary
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
 
Method Summary
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 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_DELIMITER

public static final String DEFAULT_DELIMITER
The default delimiter between table entries

See Also:
Constant Field Values

DEFAULT_COMMENT_PREFIX

public static final String DEFAULT_COMMENT_PREFIX
The default comment prefix

See Also:
Constant Field Values
Constructor Detail

GavoCSVTableParser

public GavoCSVTableParser(uk.ac.starlink.table.StoragePolicy storage,
                          Component parent)
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 Detail

getCommentPrefix

public String getCommentPrefix()
Getter for property commentPrefix.

Returns:
Value of property commentPrefix.

setDelimiter

public void setDelimiter(String delimiter)
Sets the delimiter to use.

Parameters:
delimiter - the delimiter.

getDelimiter

public String getDelimiter()
Gets the delimiter.

Returns:
a String with the delimiter.

parseLine

public List parseLine(String line)
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

public uk.ac.starlink.table.StarTable parse(InputStream stream)
                                     throws Exception
Throws:
Exception

classForJDBCType

public static Class classForJDBCType(int jdbcType)

objectForJDBCType

public static Object objectForJDBCType(int jdbcType,
                                       String value)


Copyright © 2003-2018 CCLRC: Council for the Central Laboratory of the Research Councils. All Rights Reserved.