at.dms.compiler.antlr.extra
Class InputBuffer

java.lang.Object
  extended by java.io.Reader
      extended by at.dms.compiler.antlr.extra.InputBuffer
All Implemented Interfaces:
Closeable, Readable

public class InputBuffer
extends Reader

Handles the input of compiler source code to the scanner.


Field Summary
 
Fields inherited from class java.io.Reader
lock
 
Constructor Summary
InputBuffer(File file, String encoding)
          Constructs a new input buffer that uses the specified character encoding, or the default character encoding if the specified encoding is null.
InputBuffer(String name, File file, String encoding)
          Constructs a new input buffer that uses the specified character encoding, or the default character encoding if the specified encoding is null.
 
Method Summary
 void close()
          Closes the input buffer.
 InputBufferState getBufferState(Scanner scanner)
          Exports the buffer state.
 String getFile()
          Returns the name of the file being read.
 int getLine()
          Returns the current line number in the source code.
 void incrementLine()
          Sets the current line number in the source code.
 int read(char[] cbuf, int off, int len)
          Reads characters into a portion of an array.
 void setFile(String file)
          Sets the name of the file being read.
 void setLine(int line)
          Sets the current line number in the source code.
 
Methods inherited from class java.io.Reader
mark, markSupported, read, read, read, ready, reset, skip
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

InputBuffer

public InputBuffer(String name,
                   File file,
                   String encoding)
            throws IOException
Constructs a new input buffer that uses the specified character encoding, or the default character encoding if the specified encoding is null.

Parameters:
name - the name of the file
file - the file to read
encoding - the name of a supported character encoding
Throws:
IOException - an I/O exception occurred

InputBuffer

public InputBuffer(File file,
                   String encoding)
            throws IOException
Constructs a new input buffer that uses the specified character encoding, or the default character encoding if the specified encoding is null.

Parameters:
file - the file to read
encoding - the name of a supported character encoding
Throws:
IOException - an I/O exception occurred
Method Detail

close

public void close()
           throws IOException
Closes the input buffer.

Specified by:
close in interface Closeable
Specified by:
close in class Reader
Throws:
IOException

read

public int read(char[] cbuf,
                int off,
                int len)
         throws IOException
Reads characters into a portion of an array. This method will block until some input is available, an I/O error occurs, or the end of the stream is reached. JLS 3.5 : As a special concession for compatibility with certain operating systems, the ASCII SUB character (\ u 0 0 1 a, or control-Z) is ignored if it is the last character in the escaped input.

Specified by:
read in class Reader
Parameters:
cbuf - destination buffer
off - offset at which to start storing characters
len - maximum number of characters to read
Returns:
The number of characters read, or -1 if the end of the stream has been reached
Throws:
IOException - - If an I/O error occurs

setFile

public void setFile(String file)
Sets the name of the file being read.


getFile

public String getFile()
Returns the name of the file being read.


getLine

public final int getLine()
Returns the current line number in the source code.


setLine

public final void setLine(int line)
Sets the current line number in the source code.


incrementLine

public final void incrementLine()
Sets the current line number in the source code.


getBufferState

public InputBufferState getBufferState(Scanner scanner)
Exports the buffer state.