org.extex.ocpware.engine
Class OcpReader

java.lang.Object
  extended by java.io.Reader
      extended by org.extex.ocpware.engine.OcpReader
All Implemented Interfaces:
java.io.Closeable, java.lang.Readable

public class OcpReader
extends java.io.Reader

This reader applies an ΩCP program to an input stream.

Note:
This class used buffers which are extended dynamically but not reduced. This is a potential memory leak.

Version:
$Revision: 6447 $
Author:
Gerd Neugebauer
See Also:
OcpCode

Field Summary
 
Fields inherited from class java.io.Reader
lock
 
Constructor Summary
OcpReader(java.io.Reader reader, OcpProgram program)
          Creates a new object.
 
Method Summary
 void close()
          
 int[] getArithStack()
          Getter for arithStack.
 int getCodeWord()
          Getter for the next code word.
 int getLast()
          Getter for last.
 java.lang.String getLine()
          Get the line of characters already read.
 int getPc()
          Getter for the program counter.
 OcpProgram getProgram()
          Getter for program.
 int getSomeEnd()
          Getter for someEnd.
 int getSomePtr()
          Getter for somePtr.
 int getStart()
          Getter for start.
 int getState()
          Getter for the current state.
 int read()
          
 int read(char[] cbuf, int off, int len)
          
 void register(OcpReaderObserver observer)
          Register an observer to be informed about certain events.
 java.lang.String toString()
          
 
Methods inherited from class java.io.Reader
mark, markSupported, read, read, ready, reset, skip
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

OcpReader

public OcpReader(java.io.Reader reader,
                 OcpProgram program)
          throws java.lang.IllegalArgumentException,
                 UnsupportedOutputException
Creates a new object.

Parameters:
reader - the reader for input characters. This is not allowed to be null.
program - the program code to run. This is not allowed to be null.
Throws:
java.lang.IllegalArgumentException - in case that one of the arguments is null
UnsupportedOutputException - in case of an unknown output size is encountered
Method Detail

close

public void close()
           throws java.io.IOException

Specified by:
close in interface java.io.Closeable
Specified by:
close in class java.io.Reader
Throws:
java.io.IOException
See Also:
Reader.close()

getArithStack

public int[] getArithStack()
Getter for arithStack.

Returns:
the arithStack

getCodeWord

public int getCodeWord()
                throws java.lang.ArrayIndexOutOfBoundsException
Getter for the next code word. The word returned is one past the pc. This is useful to access the second argument of a 2-argument instruction. The pc is not incremented.

Returns:
the code word
Throws:
java.lang.ArrayIndexOutOfBoundsException - in case that the requested word does not exist

getLast

public int getLast()
Getter for last.

Returns:
the last

getLine

public java.lang.String getLine()
Get the line of characters already read.

Returns:
the currently processed line as String

getPc

public int getPc()
Getter for the program counter.

Returns:
the pc

getProgram

public OcpProgram getProgram()
Getter for program.

Returns:
the program

getSomeEnd

public int getSomeEnd()
Getter for someEnd.

Returns:
the someEnd

getSomePtr

public int getSomePtr()
Getter for somePtr.

Returns:
the somePtr

getStart

public int getStart()
Getter for start.

Returns:
the start

getState

public int getState()
Getter for the current state.

Returns:
the state

read

public int read()
         throws java.io.IOException,
                OcpEmptyStackException,
                IllegalPcException

Overrides:
read in class java.io.Reader
Throws:
OcpEmptyStackException - in case of an empty stack
IllegalPcException - if the program counter points outside the code area
java.io.IOException
See Also:
Reader.read()

read

public int read(char[] cbuf,
                int off,
                int len)
         throws java.io.IOException

Specified by:
read in class java.io.Reader
Throws:
java.io.IOException
See Also:
Reader.read(char[], int, int)

register

public void register(OcpReaderObserver observer)
Register an observer to be informed about certain events.

Parameters:
observer - the observer to register

toString

public java.lang.String toString()

Overrides:
toString in class java.lang.Object
See Also:
Object.toString()