Package uk.ac.starlink.table.formats
Class CsvStarTable
- java.lang.Object
-
- uk.ac.starlink.table.AbstractStarTable
-
- uk.ac.starlink.table.formats.StreamStarTable
-
- uk.ac.starlink.table.formats.CsvStarTable
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
,StarTable
public class CsvStarTable extends StreamStarTable
Comma-Separated Value table. This reader tries to read data in the semi-standard CSV format. The intention is that it understands the version of that dialect spoken by MS Excel, though the documentation on which it is based was not obtained directly from MicroSoft.Here are the rules:
- Each row must have the same number of comma-separated fields.
- Whitespace (space or tab) adjacent to a comma is ignored.
- Adjacent commas, or a comma at the start or end of a line (whitespace apart) indicates a null field.
- Lines are terminated by any sequence of carriage-return or newline characters ('\r' or '\n') (a corollary of this is that blank lines are ignored).
- Cells may be enclosed in double quotes; quoted values may contain linebreaks (or any other character); a double quote character within a quoted value is represented by two adjacent double quotes.
- The first line may be a header line containing column names rather than a row of data. Exactly the same syntactic rules are followed for such a row as for data rows.
- Since:
- 21 Sep 2004
- Author:
- Mark Taylor (Starlink)
-
-
Field Summary
-
Fields inherited from class uk.ac.starlink.table.formats.StreamStarTable
END
-
-
Constructor Summary
Constructors Constructor Description CsvStarTable(uk.ac.starlink.util.DataSource datsrc)
Constructor with default options.CsvStarTable(uk.ac.starlink.util.DataSource datsrc, java.lang.Boolean fixHasHeaderLine, int maxSample)
Constructor with configuration option.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected java.io.PushbackInputStream
getInputStream()
Convenience method which returns a buffered pushback stream based on this table's data source.protected RowEvaluator.Metadata
obtainMetadata()
Obtains column metadata for this table, probably by reading through the rows once and using a RowEvaluator.protected java.util.List<java.lang.String>
readRow(java.io.PushbackInputStream in)
Reads the next row of data from a given stream.-
Methods inherited from class uk.ac.starlink.table.formats.StreamStarTable
getColumnCount, getColumnInfo, getRowCount, getRowSequence, init
-
Methods inherited from class uk.ac.starlink.table.AbstractStarTable
checkedLongToInt, close, getCell, getColumnAuxDataInfos, getName, getParameters, getRow, getRowAccess, getRowSplittable, getURL, isRandom, setName, setParameters, setURL
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface uk.ac.starlink.table.StarTable
getParameterByName, setParameter
-
-
-
-
Constructor Detail
-
CsvStarTable
public CsvStarTable(uk.ac.starlink.util.DataSource datsrc) throws TableFormatException, java.io.IOException
Constructor with default options.- Parameters:
datsrc
- data source- Throws:
TableFormatException
java.io.IOException
-
CsvStarTable
public CsvStarTable(uk.ac.starlink.util.DataSource datsrc, java.lang.Boolean fixHasHeaderLine, int maxSample) throws TableFormatException, java.io.IOException
Constructor with configuration option.- Parameters:
datsrc
- data sourcefixHasHeaderLine
- indicates whether initial line is known to be column names: yes, no or auto-determinemaxSample
- maximum number of rows sampled to determine column data types; if <=0, all rows are sampled- Throws:
TableFormatException
java.io.IOException
-
-
Method Detail
-
getInputStream
protected java.io.PushbackInputStream getInputStream() throws java.io.IOException
Description copied from class:StreamStarTable
Convenience method which returns a buffered pushback stream based on this table's data source.- Overrides:
getInputStream
in classStreamStarTable
- Returns:
- input stream containing source data
- Throws:
java.io.IOException
-
obtainMetadata
protected RowEvaluator.Metadata obtainMetadata() throws TableFormatException, java.io.IOException
Description copied from class:StreamStarTable
Obtains column metadata for this table, probably by reading through the rows once and using a RowEvaluator.- Specified by:
obtainMetadata
in classStreamStarTable
- Returns:
- information about the table represented by the character stream
- Throws:
TableFormatException
- if the data doesn't represent this kind of tablejava.io.IOException
- if I/O error is encountered
-
readRow
protected java.util.List<java.lang.String> readRow(java.io.PushbackInputStream in) throws java.io.IOException
Reads the next row of data from a given stream. Ignorable rows are skipped; comments may be stashed away.- Specified by:
readRow
in classStreamStarTable
- Parameters:
in
- input stream- Returns:
- list of Strings one for each cell in the row, or null for end of stream
- Throws:
TableFormatException
- if the data doesn't represent this kind of tablejava.io.IOException
- if I/O error is encountered
-
-