Package moss

Class TableReader

All Implemented Interfaces:
Closeable, AutoCloseable, Readable
Direct Known Subclasses:
GraphReader

public class TableReader extends PushbackReader
Class for readers for simple table formats.
Since:
2007.03.04
  • Field Details

    • RECSEP

      public static final int RECSEP
      class/type flag: record separator
      See Also:
    • FLDSEP

      public static final int FLDSEP
      class/type flag: field separator
      See Also:
    • BLANK

      public static final int BLANK
      class/type flag: blank character
      See Also:
    • COMMENT

      public static final int COMMENT
      class/type flag: comment character
      See Also:
    • cflags

      protected char[] cflags
      the character flags
    • buf

      protected StringBuilder buf
      the buffer for the next table field
    • field

      protected String field
      the next table field
    • delim

      protected int delim
      the last delimiter read: -1 if end of file/input, 0 if field separator, 1 if record separator
    • recno

      protected int recno
      the current record number
  • Constructor Details

    • TableReader

      public TableReader(Reader reader)
      Create a table reader with default character flags.

      By default the following character settings are used:
      record separators: "\n", field separators: " \t", blanks: " \r\t", comment characters: "#".

      Parameters:
      reader - the reader to work on
      Since:
      2006.10.05 (Christian Borgelt)
  • Method Details

    • setChars

      public void setChars(int type, String chars)
      Set the characters for a specific type/class.
      Parameters:
      type - the type/class of the characters to set; must be one of the constants RECSEP, FLDSEP, BLANK, or COMMENT (or a combination of these, by binary or)
      chars - the characters to set
      Since:
      2007.06.26 (Christian Borgelt)
    • setChars

      public void setChars(String recseps, String fldseps, String blanks, String comment)
      Set the characters for all types.

      If a parameter is null, the corresponding character flags are maintained.

      Parameters:
      recseps - the record separators
      fldseps - the field separators
      blanks - the blank characters
      comment - the comment characters
      Since:
      2007.05.17 (Christian Borgelt)
    • isType

      public boolean isType(int type, char c)
      Check whether a given character is in a given class or of a given type.
      Parameters:
      type - the type/class for which to query; must be one of the constants RECSEP, FLDSEP, BLANK, or COMMENT
      c - the character to query
      Returns:
      whether the character is in the given class
      Since:
      2006.10.06 (Christian Borgelt)
    • getTypes

      public int getTypes(char c)
      Get the classes/types of a given character.
      Parameters:
      c - the character to query
      Returns:
      the classes character is in, as a combination of the flags RECSEP, FLDSEP, BLANK, or COMMENT
      Since:
      2006.10.06 (Christian Borgelt)
    • rno

      public String rno()
      Get a string stating the current record number. Useful for error reporting.
      Returns:
      a string stating the current record number in the format "(record xxx)"
      Since:
      2007.01.31 (Christian Borgelt)
    • rno

      public String rno(int offset)
      Get a string stating the current record number.

      Useful for error reporting.

      Parameters:
      offset - the offset to add to the record number
      Returns:
      a string stating the current record number in the format "(record xxx)"
      Since:
      2007.03.29 (Christian Borgelt)
    • eof

      public boolean eof() throws IOException
      Check for end of file.
      Returns:
      whether at end of file
      Throws:
      IOException - if reading the next character failed
      Since:
      2020.10.25 (Christian Borgelt)
    • readField

      public int readField() throws IOException
      Read the next field/cell of the table.

      Note that a record separator is (virtually) inserted at the end of the file/input if the file/input does not end with a record separator.

      Returns:
      the type of the delimiter of the field read: -1, if end of file/input, 0, if field separator, +1, if record separator.
      Throws:
      IOException - if an i/o error occurs
      Since:
      2006.10.05/2007.06.26 (Christian Borgelt)