Package hsa

Class TextInputFile


  • public class TextInputFile
    extends java.lang.Object
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected boolean closed
      Set if the file has been closed.
      protected static int EMPTY
      Constants and variables used by the input line buffer.
      protected boolean eofFlag
      The end-of-file flag
      protected java.io.BufferedReader f
      Stream used for reading input.
      protected java.lang.String fileName
      The file name.
      protected java.lang.String lineBuffer  
      protected boolean useStandardIO
      Indicator whether to write to standard output or a file.
    • Constructor Summary

      Constructors 
      Constructor Description
      TextInputFile()
      Contructor - TextInputFile to read from standard input.
      TextInputFile​(java.io.File file)
      Contructor - TextInputFile to read from a File.
      TextInputFile​(java.lang.String fileName)
      Contructor - TextInputFile to read from file with specified name.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()
      Close the file to further reading.
      boolean eof()
      Return whether there is an eof before the next token.
      protected void pushACharacter​(char ch)
      Place the character in the unread position.
      protected char readACharacter()
      Read a single character from the file.
      protected char readACharacterThrowsEOF()
      Read a single character from the file.
      protected void readALineFromFile()
      Reads a line from the file.
      protected java.lang.String readAToken()
      Reads in input from the keyboard buffer until it hits a whitespace, which indicates the end of a token.
      boolean readBoolean()
      Read a boolean from the file.
      byte readByte()
      Read an 8-bit integer (a "byte") from the file.
      char readChar()
      Read a single character from the file.
      double readDouble()
      Read a double precision floating point number (a "double") from the file.
      float readFloat()
      Read a floating point number (a "float") from the file.
      int readInt()
      Read a 32-bit integer (an "int") from the file.
      java.lang.String readLine()
      Read a full line of text from the file.
      long readLong()
      Read a 64-bit integer (a "long") from the file.
      short readShort()
      Read a 16-bit integer (a "short") from the file.
      java.lang.String readString()
      Read a whitespace delimited token from the file.
      • Methods inherited from class java.lang.Object

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

      • fileName

        protected java.lang.String fileName
        The file name.
      • f

        protected java.io.BufferedReader f
        Stream used for reading input.
      • closed

        protected boolean closed
        Set if the file has been closed.
      • useStandardIO

        protected boolean useStandardIO
        Indicator whether to write to standard output or a file.
      • eofFlag

        protected boolean eofFlag
        The end-of-file flag
      • EMPTY

        protected static final int EMPTY
        Constants and variables used by the input line buffer.
        See Also:
        Constant Field Values
      • lineBuffer

        protected java.lang.String lineBuffer
    • Constructor Detail

      • TextInputFile

        public TextInputFile()
        Contructor - TextInputFile to read from standard input.
      • TextInputFile

        public TextInputFile​(java.io.File file)
        Contructor - TextInputFile to read from a File.
        Parameters:
        file - - File to be opened.
      • TextInputFile

        public TextInputFile​(java.lang.String fileName)
        Contructor - TextInputFile to read from file with specified name.
        Parameters:
        fileName - - Name of the file to be opened.
    • Method Detail

      • close

        public void close()
        Close the file to further reading.
      • eof

        public boolean eof()
        Return whether there is an eof before the next token.
        Returns:
        Whether there is an eof before the next token
      • pushACharacter

        protected void pushACharacter​(char ch)
        Place the character in the unread position. The next time a character is read, this one will be returned.
        Parameters:
        ch - - The character to be pushed into the unread position.
      • readACharacter

        protected char readACharacter()
        Read a single character from the file. If we reach EOF before reading the character, display an error message and exit.
        Returns:
        The character read from the file.
      • readACharacterThrowsEOF

        protected char readACharacterThrowsEOF()
                                        throws java.io.EOFException
        Read a single character from the file.
        Returns:
        The character read from the file.
        Throws:
        java.io.EOFException - - Thrown if attempt to read past EOF.
      • readALineFromFile

        protected void readALineFromFile()
                                  throws java.io.EOFException
        Reads a line from the file.
        Throws:
        java.io.EOFException - - Thrown if attempt to read past EOF.
      • readAToken

        protected java.lang.String readAToken()
        Reads in input from the keyboard buffer until it hits a whitespace, which indicates the end of a token.
      • readBoolean

        public boolean readBoolean()
        Read a boolean from the file. The actual text in the file must be either "true" or "false" although case is irrelvant.
        Returns:
        The boolean value read from the file.
      • readByte

        public byte readByte()
        Read an 8-bit integer (a "byte") from the file. The actual text in the file must be a number from -128 to 127.
        Returns:
        The byte value read from the file.
      • readChar

        public char readChar()
        Read a single character from the file. Note that this discards any whitespace. If you want to get every character on the line, use the readLine () method.
        Returns:
        The character read from the file.
      • readDouble

        public double readDouble()
        Read a double precision floating point number (a "double") from the file.
        Returns:
        The double value read from the file.
      • readFloat

        public float readFloat()
        Read a floating point number (a "float") from the file.
        Returns:
        The float value read from the file.
      • readInt

        public int readInt()
        Read a 32-bit integer (an "int") from the file. The actual text in the file must be a number from -2147483648 to 2147483647.
        Returns:
        The int value read from the file.
      • readLine

        public java.lang.String readLine()
        Read a full line of text from the file.
        Returns:
        The line of text read from the file.
      • readLong

        public long readLong()
        Read a 64-bit integer (a "long") from the file.
        Returns:
        The long value read from the file.
      • readShort

        public short readShort()
        Read a 16-bit integer (a "short") from the file. The actual text in the file must be a number from -32768 to 32767.
        Returns:
        The short value read from the file.
      • readString

        public java.lang.String readString()
        Read a whitespace delimited token from the file.
        Returns:
        The token read from the file.