ESC/Java2
© 2003,2004,2005 David Cok and Joseph Kiniry
© 2005 UCD Dublin
© 2003,2004 Radboud University Nijmegen
© 1999,2000 Compaq Computer Corporation
© 1997,1998,1999 Digital Equipment Corporation
All Rights Reserved

javafe.util
Class CorrelatedReader

java.lang.Object
  extended byjavafe.util.CorrelatedReader
Direct Known Subclasses:
BufferedCorrelatedReader, FilterCorrelatedReader

public abstract class CorrelatedReader
extends java.lang.Object

A reader (aka input stream) that provides an associated location with each character read.

See javafe.util.Location for the interpretation of these locations.

This class also takes care of unicode conversion. A unicode character sequence consists of a backslash that is preceded by an even number of backslashes, followed by one or more 'u's, followed by four hexadecimal digits. This class converts each unicode character sequence into a single character.

This class also provides the ability to mark a specific point in the input stream, and to reposition the stream at the marked position. We also provide a method to create a new CorrelatedReader for the text between the marked position and the current point in the stream. Marking is also allowed on the new CorrelatedReader object. For efficiency, we also provide the facility to remove the mark from the stream.

Author:
Cormac Flanagan
See Also:
Location

Field Summary
protected  boolean marked
          True iff a mark has been set.
 
Constructor Summary
protected CorrelatedReader()
          Simple constructor.
 
Method Summary
abstract  void clearMark()
          Removes the mark (if any) from the input stream.
 void close()
          Closes us.
abstract  CorrelatedReader createReaderFromMark(int discard)
          Creates a CorrelatedReader object for the input text from the marked position, to the current position.
abstract  GenericFile getFile()
          Returns the file underlying this correlated reader.
abstract  int getLocation()
          Returns the location of the last character read.
abstract  void mark()
          Marks the position of the current character in this input stream.
abstract  int read()
          Reads the next character from this input stream.
abstract  void reset()
          Repositions this stream to the position at the time the mark method was last called on this input stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

marked

protected boolean marked
True iff a mark has been set.

Constructor Detail

CorrelatedReader

protected CorrelatedReader()
Simple constructor. Pretty boring, really.

Method Detail

getFile

public abstract GenericFile getFile()
Returns the file underlying this correlated reader.


getLocation

public abstract int getLocation()
Returns the location of the last character read. If no character has been read yet, returns a whole-file location for this file.


mark

public abstract void mark()
Marks the position of the current character in this input stream. A subsequent call to the reset method repositions this stream at the last marked position.

This method differs from java.io.InputStream.readlimit in that it does not take a readlimit argument.

See Also:
reset(), clearMark(), createReaderFromMark(int)

clearMark

public abstract void clearMark()
Removes the mark (if any) from the input stream.

See Also:
mark()

reset

public abstract void reset()
                    throws java.io.IOException
Repositions this stream to the position at the time the mark method was last called on this input stream.

Requires that the input stream had been previously marked via the mark() method.

If mark() is called before read(), then the mark will be restored to its previous value (and not the preceeding character().

Throws:
java.io.IOException - if this stream is not marked.
See Also:
mark()

createReaderFromMark

public abstract CorrelatedReader createReaderFromMark(int discard)
                                               throws java.lang.IndexOutOfBoundsException
Creates a CorrelatedReader object for the input text from the marked position, to the current position.

Calls to getLocation() for characters from the new CorrelatedReader yield the same locations as calls to getLocation() for the same characters on this CorrelatedReader.

The discard argument specifies the number of characters to discard from the end of the sub-CorrelatedReader.

Clears the mark as a side-effect.

Requires that the input stream had been previously marked via the mark() method and that we have not been closed.

Throws:
java.lang.IndexOutOfBoundsException - if discard is negative or exceeds the number of marked characters
See Also:
BufferedCorrelatedReader.mark()

close

public void close()
Closes us. No other I/O operations may be called on us after we have been closed.


read

public abstract int read()
                  throws java.io.IOException
Reads the next character from this input stream. Does unicode conversion.

Requires we are open.

Returns:
A unicode character, or -1.

Throws:
java.io.IOException

ESC/Java2
© 2003,2004,2005 David Cok and Joseph Kiniry
© 2005 UCD Dublin
© 2003,2004 Radboud University Nijmegen
© 1999,2000 Compaq Computer Corporation
© 1997,1998,1999 Digital Equipment Corporation
All Rights Reserved

The ESC/Java2 Project Homepage