Class Information
Package: com.onepg.util
Class Name: IoTsvReader
Description
TSV reader class for data I/O.
- Wrapper class for the text reader
TxtReader. - Declare in a try clause (try-with-resources statement).
- Provides an iterator that returns each TSV row as
IoItems. - Uses the first row of the file as column names and as keys for
IoItems. - Key names must be valid as
IoItemsobject keys. (key rule ofAbstractIoTypeMap) - Assumes the file encoding is UTF-8 and the line separator is LF.
- Assumes that newline characters (CRLF, CR, LF) and tab characters within values are escaped.
[Example]
try (final IoTsvReader tr = new IoTsvReader(filePath);) {
for (final IoItems items : tr) {
: (omitted)
}
}
Method List
iterator
public Iterator<IoItems> iterator()
Creates an iterator.
Return Value
Iterator<IoItems> - the TSV row iterator
close
public void close()
Closes the file.
getKeys
public String[] getKeys()
Retrieves the key array.
- Returns the key array retrieved from the first row of the file.
- Returns an empty array if the file has zero rows.
getReadedCount
public int getReadedCount()
Retrieves the number of rows read (excluding the header row).
- Returns the number of rows read by the iterator.
- The first row is not counted when it is used as the key (header row).
Return Value
int - the number of rows read
isReadedEndRow
public boolean isReadedEndRow()
Checks if the last row has been read.
Return Value
boolean - true if the last row has been read
hasNext
public boolean hasNext()
Checks if the next row exists.
Return Value
boolean - true if the next row exists
next
public IoItems next()
Retrieves the next row.
- Stores the TSV row in
IoItemsand returns it.
Return Value
IoItems - the IoItems containing the TSV row