Class LineReader

java.lang.Object
java.io.Reader
java.io.BufferedReader
org.moeaframework.util.io.LineReader
All Implemented Interfaces:
Closeable, AutoCloseable, Iterable<String>, Readable, Iterator<String>

public class LineReader extends BufferedReader implements Iterable<String>, Iterator<String>
Read lines from a character-input stream, with options to ignore blank and commented lines.
  • Constructor Details

    • LineReader

      public LineReader(Reader in)
      Constructs a new line reader.
      Parameters:
      in - a reader
  • Method Details

    • wrap

      public static LineReader wrap(Reader reader)
      Wraps the given reader in a line reader.
      Parameters:
      reader - the reader
      Returns:
      the reader wrapped in a line reader
    • skipComments

      public LineReader skipComments()
      Configures this reader to skip any lines starting with the comment prefix.
      Returns:
      a reference to this reader
    • skipBlanks

      public LineReader skipBlanks()
      Configures this reader to skip any lines that contain only whitespace.
      Returns:
      a reference to this reader
    • trim

      public LineReader trim()
      Configures this reader to trim any leading and trailing whitespace from each line.
      Returns:
      a reference to this reader
    • commentPrefix

      public LineReader commentPrefix(String commentPrefix)
      Configures the prefix string used to identify comment lines.
      Parameters:
      commentPrefix - the prefix string used to identify comments
      Returns:
      a reference to this reader
    • readLine

      public String readLine() throws IOException
      Overrides:
      readLine in class BufferedReader
      Throws:
      IOException
    • iterator

      public Iterator<String> iterator()
      Specified by:
      iterator in interface Iterable<String>
    • hasNext

      public boolean hasNext()
      Specified by:
      hasNext in interface Iterator<String>
    • next

      public String next()
      Specified by:
      next in interface Iterator<String>
    • transferTo

      public long transferTo(Writer out) throws IOException
      Overrides:
      transferTo in class Reader
      Throws:
      IOException
    • last

      public String last()
      Returns the last line in the reader, skipping any intermediate lines.
      Returns:
      the last line