Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| 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
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## javafe.util
Class BufferedCorrelatedReader

    java.lang.Object
      javafe.util.CorrelatedReader
          javafe.util.BufferedCorrelatedReader

Direct Known Subclasses:
  LocationManagerCorrelatedReader, SubCorrelatedReader

public abstract class BufferedCorrelatedReader
extends CorrelatedReader

Instances of this `CorrelatedReader` contain a buffer.

Field Summary
`protected int` | `beforeBufLoc` The location of the first character in the buffer, minus 1.
`protected byte[]` | `buf` While open, we buffer input in the buffer `buf`, which grows on demand.
`protected int` | `curNdx` The index of the next character to be read from the buffer.
`protected int` | `endBufNdx` The first unused entry in the buffer.
`protected int` | `lastCharNdx` The value of curNdx for the last character read, or, if no characters have been read yet, the value of curNdx.
`protected int` | `markNdx` The value of curNdx at the mark point (if marked is true).
`protected int` | `maxLoc`
`protected int` | `minLoc` The allocated location range for this CorrelatedReader instance is [minLoc, maxLoc).
`protected int` | `oddSlashLoc` For unicode conversion, we need to know if we have just seen an even or odd number of backslashes.
`(package private) static int` | `STARTFREELOC` All locations are allocated at or above a medium-large int STARTFREELOC to make it less likely that other program ints can be interpreted as locations.

Fields inherited from class javafe.util.CorrelatedReader
`marked`

Constructor Summary
`(package private)` | `BufferedCorrelatedReader(int minLoc, int beforeBufLoc, int maxLoc)` This constructor leaves `buf` as null.

Method Summary
`void` | `clearMark()` Removes the mark (if any) from the input stream.
`void` | `close()` Closes us.
`CorrelatedReader` | `createReaderFromMark(int discard)` Creates a `CorrelatedReader` object for the input text from the marked position, to the current position.
`int` | `getBeforeMarkLocation()` Returns the location of the character before the mark.
`byte[]` | `getBufferFromMark(int discard)` Returns a new buffer containing the contents of this BufferedCorrelatedReader's buffer, from the marked position to the current position less `discard` bytes (not characters).
`int` | `getLocation()` Returns the location of the last character read.
`void` | `mark()` Marks the position of the current character in this input stream.
`protected int` | `peek()` Peeks the next character from this input stream.
`protected int` | `readRaw()` Reads the next character from this input stream.
`protected abstract boolean` | `refillBuf()` Refills the buffer.
`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 javafe.util.CorrelatedReader
`getFile, read`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### STARTFREELOC

    static final int STARTFREELOC

  All locations are allocated at or above a medium-large int STARTFREELOC to make it less likely that other program ints can be interpreted as locations.

  See Also:
    Constant Field Values

### minLoc

    protected int minLoc

  The allocated location range for this CorrelatedReader instance is [minLoc, maxLoc).

  Note that in practice only a prefix, [minLoc, min(beforeBufLoc + curNdx, maxLoc-1)], of the range representing the characters read so far are actually valid locations at any given time.

### maxLoc

    protected int maxLoc

### buf

    protected byte[] buf

  While open, we buffer input in the buffer `buf`, which grows on demand. We are closed iff `buf` is non-null.

### beforeBufLoc

    protected int beforeBufLoc

  The location of the first character in the buffer, minus 1.

  The locations of later valid characters are obtained by adding their index to this loc.

### endBufNdx

    protected int endBufNdx

  The first unused entry in the buffer. Aka, buf[0]...buf[endBufNdx-1] contains valid data (if buf != null).

### curNdx

    protected int curNdx

  The index of the next character to be read from the buffer. If equal to endBufNdx, then we need to read more from the stream.

### lastCharNdx

    protected int lastCharNdx

  The value of curNdx for the last character read, or, if no characters have been read yet, the value of curNdx. Note that because of unicode conversion, this may not be just curNdx-1. This exists because mark() marks from just before the last character read, not the current position.

### oddSlashLoc

    protected int oddSlashLoc

  For unicode conversion, we need to know if we have just seen an even or odd number of backslashes. Accordingly, we record the location of the last odd backslash read (Location.NULL if one has not been seen yet).

### markNdx

    protected int markNdx

  The value of curNdx at the mark point (if marked is true).

Constructor Detail

### BufferedCorrelatedReader

    BufferedCorrelatedReader(int minLoc,
                             int beforeBufLoc,
                             int maxLoc)

  This constructor leaves `buf` as null.

Method Detail

### close

    public void close()

  Closes us. No other I/O operations may be called on us after we have been closed.

  Overrides:
    `close` in class `CorrelatedReader`

### getLocation

    public 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.

  Specified by:
    `getLocation` in class `CorrelatedReader`

### refillBuf

    protected abstract boolean refillBuf()
                                  throws java.io.IOException

  Refills the buffer.

  In doing so, may reallocate the buffer.

  Returns true iff not end-of-file, and at least one character was read from the file. Throws an IOException if no characters could be read from the stream.

  Requires we are open.

  Throws:
    `java.io.IOException`

### peek

    protected int peek()
                throws java.io.IOException

  Peeks the next character from this input stream. Does no unicode conversion.

  Requires we are open.

  Throws:
    `java.io.IOException`

### readRaw

    protected int readRaw()
                   throws java.io.IOException

  Reads the next character from this input stream. Does no unicode conversion.

  Requires we are open.

  Throws:
    `java.io.IOException`

### mark

    public 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.

  Specified by:
    `mark` in class `CorrelatedReader`
  See Also:
    `reset()`, `clearMark()`, `createReaderFromMark(int)`

### clearMark

    public void clearMark()

  Removes the mark (if any) from the input stream.

  Specified by:
    `clearMark` in class `CorrelatedReader`
  See Also:
    `mark()`

### reset

    public 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().

  Specified by:
    `reset` in class `CorrelatedReader`
  Throws:
    `java.io.IOException` - if this stream is not marked.
  See Also:
    `mark()`

### getBeforeMarkLocation

    public int getBeforeMarkLocation()

  Returns the location of the character before the mark.

### getBufferFromMark

    public byte[] getBufferFromMark(int discard)
                             throws java.lang.IndexOutOfBoundsException

  Returns a new buffer containing the contents of this BufferedCorrelatedReader's buffer, from the marked position to the current position less `discard` bytes (not characters). Clears the mark as a side-effect.

  Throws:
    `java.lang.IndexOutOfBoundsException` - if `discard` is negative or exceeds the number of marked characters

### createReaderFromMark

    public 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.

  Specified by:
    `createReaderFromMark` in class `CorrelatedReader`
  Throws:
    `java.lang.IndexOutOfBoundsException` - if `discard` is negative or exceeds the number of marked characters
  See Also:
    `mark()`

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| 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
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

The ESC/Java2 Project Homepage