Package moss
Class TableReader
java.lang.Object
java.io.Reader
java.io.FilterReader
java.io.PushbackReader
moss.TableReader
- All Implemented Interfaces:
Closeable
,AutoCloseable
,Readable
- Direct Known Subclasses:
GraphReader
Class for readers for simple table formats.
- Since:
- 2007.03.04
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
class/type flag: blank characterprotected StringBuilder
the buffer for the next table fieldprotected char[]
the character flagsstatic final int
class/type flag: comment characterprotected int
the last delimiter read: -1 if end of file/input, 0 if field separator, 1 if record separatorprotected String
the next table fieldstatic final int
class/type flag: field separatorprotected int
the current record numberstatic final int
class/type flag: record separatorFields inherited from class java.io.FilterReader
in
-
Constructor Summary
ConstructorsConstructorDescriptionTableReader
(Reader reader) Create a table reader with default character flags. -
Method Summary
Modifier and TypeMethodDescriptionboolean
eof()
Check for end of file.int
getTypes
(char c) Get the classes/types of a given character.boolean
isType
(int type, char c) Check whether a given character is in a given class or of a given type.int
Read the next field/cell of the table.rno()
Get a string stating the current record number.rno
(int offset) Get a string stating the current record number.void
Set the characters for a specific type/class.void
Set the characters for all types.Methods inherited from class java.io.PushbackReader
close, mark, markSupported, read, read, ready, reset, skip, unread, unread, unread
Methods inherited from class java.io.Reader
nullReader, read, read, transferTo
-
Field Details
-
RECSEP
public static final int RECSEPclass/type flag: record separator- See Also:
-
FLDSEP
public static final int FLDSEPclass/type flag: field separator- See Also:
-
BLANK
public static final int BLANKclass/type flag: blank character- See Also:
-
COMMENT
public static final int COMMENTclass/type flag: comment character- See Also:
-
cflags
protected char[] cflagsthe character flags -
buf
the buffer for the next table field -
field
the next table field -
delim
protected int delimthe last delimiter read: -1 if end of file/input, 0 if field separator, 1 if record separator -
recno
protected int recnothe current record number
-
-
Constructor Details
-
TableReader
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
Set the characters for a specific type/class.- Parameters:
type
- the type/class of the characters to set; must be one of the constantsRECSEP
,FLDSEP
,BLANK
, orCOMMENT
(or a combination of these, by binary or)chars
- the characters to set- Since:
- 2007.06.26 (Christian Borgelt)
-
setChars
Set the characters for all types.If a parameter is
null
, the corresponding character flags are maintained.- Parameters:
recseps
- the record separatorsfldseps
- the field separatorsblanks
- the blank characterscomment
- 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 constantsRECSEP
,FLDSEP
,BLANK
, orCOMMENT
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
, orCOMMENT
- Since:
- 2006.10.06 (Christian Borgelt)
-
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
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
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
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)
-