Class AsciiStarTable

All Implemented Interfaces:
Closeable, AutoCloseable, StarTable

public class AsciiStarTable extends StreamStarTable
Simple ASCII-format table. This reader attempts to make sensible decisions about what is a table and what is not, but inevitably it will not be able to read ASCII tables in any format.

Here are the rules:

  • Bytes in the file are interpreted as ASCII characters
  • Each table row is represented by a single line of text
  • Lines are terminated by one or more contiguous line termination characters: line feed (0x0A) or carriage return (0x0D)
  • Within a line, fields are separated by one or more whitespace characters: space (" ") or tab (0x09)
  • A field is either an unquoted sequence of non-whitespace characters, or a sequence of non-newline characters between matching single (') or double (") quote characters - spaces are therefore allowed in quoted fields
  • Within a quoted field, whitespace characters are permitted and are treated literally
  • Within a quoted field, any character preceded by a backslash character ("\") is treated literally. This allows quote characters to appear within a quoted string.
  • An empty quoted string (two adjacent quotes) or the string "null" (unquoted) represents the null value
  • All data lines must contain the same number of fields (this is the number of columns in the table)
  • The data type of a column is guessed according to the fields that appear in the table. If all the fields in one column can be parsed as integers (or null values), then that column will turn into an integer-type column. The types that are tried, in order of preference, are: Boolean, Short Integer, Long, Float, Double, String
  • Empty lines are ignored
  • Anything after a hash character "#" (except one in a quoted string) on a line is ignored as far as table data goes; any line which starts with a "!" is also ignored. However, lines which start with a "#" or "!" at the start of the table (before any data lines) will be interpreted as metadata as follows:
    • The last "#"/"!"-starting line before the first data line may contain the column names. If it has the same number of fields as there are columns in the table, each field will be taken to be the title of the corresponding column. Otherwise, it will be taken as a normal comment line.
    • Any comment lines before the first data line not covered by the above will be concatenated to form the "description" parameter of the table.
Author:
Mark Taylor (Starlink)
  • Constructor Details

    • AsciiStarTable

      public AsciiStarTable(uk.ac.starlink.util.DataSource datsrc) throws TableFormatException, IOException
      Constructor with default options.
      Parameters:
      datsrc - the data source containing the table text
      Throws:
      TableFormatException - if the input stream doesn't appear to form a ASCII-format table
      IOException - if some I/O error occurs
    • AsciiStarTable

      public AsciiStarTable(uk.ac.starlink.util.DataSource datsrc, int maxSample) throws TableFormatException, IOException
      Constructor with configuration option.
      Parameters:
      datsrc - the data source containing the table text
      maxSample - maximum number of rows sampled to determine column data types; if <=0, all rows are sampled
      Throws:
      TableFormatException - if the input stream doesn't appear to form a ASCII-format table
      IOException - if some I/O error occurs
  • Method Details