TxtReader

Framework Components [com.onepg.util]

← Back to Class List

Class Information

Package: com.onepg.util

Class Name: TxtReader

Description

Text reader class.
  • Wrapper class for file reader BufferedReader.
  • Declares in try clause (try-with-resources statement).
[Example]
try (final TxtReader tr = new TxtReader(filePath, ValUtil.UTF8);) {
  // Skips header row
  tr.skip();
  for (final String line : tr) {
    : Omitted
  }
}

Method List

iterator

public Iterator<String> iterator()
Creates iterator.

Return Value

Iterator<String> - Read row iterator

close

public void close()
Closes file.

getReadedCount

public int getReadedCount()
Gets read row count.
  • Returns the count read by the iterator.

Return Value

int - Read row count

isReadedEndRow

public boolean isReadedEndRow()
Checks if last row has been read.

Return Value

boolean - true if last row has been read

getFirstLine

public String getFirstLine()
Gets first row.
  • Gets the first row of the file.
  • Read row count is counted up after retrieval.
  • Returns null in the following cases
    • File is already closed.
    • File is empty (zero rows), or has already reached the last row.
  • An exception is thrown if any rows have already been read.

Return Value

String - First row string

hasNext

public boolean hasNext()
Checks next row.
  • Closes file reader if next row does not exist in case try clause was not used.
  • Does not recheck on consecutive hasNext() calls.

Return Value

boolean - true if next row exists