Package jminusminus

Class CharReader

java.lang.Object
jminusminus.CharReader

class CharReader extends Object
A buffered character reader, which abstracts out differences between platforms, mapping all new lines to '\n', and also keeps track of line numbers.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final char
    Representation of the end of file as a character.
  • Constructor Summary

    Constructors
    Constructor
    Description
    CharReader(String fileName)
    Constructs a CharReader from a file name.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Closes the file.
    Returns the file name.
    int
    Returns the current line number in the source file.
    char
    Scans and returns the next character.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • EOFCH

      public static final char EOFCH
      Representation of the end of file as a character.
      See Also:
  • Constructor Details

  • Method Details

    • nextChar

      public char nextChar() throws IOException
      Scans and returns the next character.
      Returns:
      the character scanned.
      Throws:
      IOException - if an I/O error occurs.
    • line

      public int line()
      Returns the current line number in the source file.
      Returns:
      the current line number in the source file.
    • fileName

      public String fileName()
      Returns the file name.
      Returns:
      the file name.
    • close

      public void close() throws IOException
      Closes the file.
      Throws:
      IOException - if an I/O error occurs.