Class Reader

java.lang.Object
io.github.kelsoncm.fwf.readers.Reader
All Implemented Interfaces:
Iterable<Map<String,Object>>, Iterator<Map<String,Object>>

public class Reader extends Object implements Iterable<Map<String,Object>>, Iterator<Map<String,Object>>
Sequential reader for Fixed Width Files.

Implements Iterable and Iterator to stream fixed-width records line by line as structured maps. Validates line size and line break delimiters during initialization.

  • Constructor Details

    • Reader

      public Reader(Object iterable, FileDescriptor fileDescriptor, String newline)
      Constructs a new Reader with a content source, file descriptor, and newline delimiter.
      Parameters:
      iterable - source object (String, List of Strings, InputStream, or java.io.Reader)
      fileDescriptor - non-null FileDescriptor
      newline - newline delimiter string ("\n", "\r", or "\n\r")
      Throws:
      IllegalArgumentException - if any argument is invalid or line sizes do not match
    • Reader

      public Reader(Object iterable, FileDescriptor fileDescriptor)
      Constructs a new Reader defaulting to newline delimiter "\n\r".
      Parameters:
      iterable - source object
      fileDescriptor - non-null FileDescriptor
  • Method Details

    • getLinesCount

      public int getLinesCount()
      Gets the total number of lines in the file.
      Returns:
      line count
    • getLineNum

      public int getLineNum()
      Gets the 1-based index of the line currently being processed.
      Returns:
      current 1-based line number
    • iterator

      public Iterator<Map<String,Object>> iterator()
      Returns an iterator over the parsed row maps.
      Specified by:
      iterator in interface Iterable<Map<String,Object>>
      Returns:
      iterator
    • hasNext

      public boolean hasNext()
      Checks if more lines remain to be read.
      Specified by:
      hasNext in interface Iterator<Map<String,Object>>
      Returns:
      true if lines remain, false otherwise
    • next

      public Map<String,Object> next()
      Reads and parses the next line into a map of column names to parsed values.
      Specified by:
      next in interface Iterator<Map<String,Object>>
      Returns:
      parsed row map
      Throws:
      NoSuchElementException - if no more lines remain