util

## Class ReaderLinesTracker

- java.lang.Object
- - util.ReaderLinesTracker

-     public class ReaderLinesTracker
      extends java.lang.Object

  A reader lines tracker is a scanner which maintains a current viewing "window" on the sequence of lines represented by a given Reader, this window being defined by "back" and "front" location markers. Each location is defined by a pair, as defined by the nested static class `ReaderLinesTracker.Loc`. Note that, in deference to XML locators, both lines and columns (within documents and lines, respectively) are numbered from 1 rather than 0. The primary motivation for the definition of this class is to support the extraction of individual elements from an XML document under the control of a SAX parser. The public interface allows the back and front markers defining the viewing window to be advanced, allows a segment to be extracted from within the window, and allows a line within the window to be searched for a given string.

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `ReaderLinesTracker(java.io.File f)` Constructs a new tracker for the given file.
    `ReaderLinesTracker(java.io.Reader rdr)` Constructs a new tracker for the given reader.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `advanceBack(int lnlo, int collo)` Advances this tracker's "back" marker to the location with the specified line and column numbers.
    `void` | `advanceFront(int lnhi, int colhi)` Advances this tracker's front marker to the location with the specified line and column numbers.
    `void` | `close()` Closes this tracker along with the reader that backs it.
    `int` | `findInLine(int i, java.lang.String s)` Given the number of a line within this tracker's current viewing window, and a search string, this method returns the column number within the line of the specified line of (the first occurrence of) the specified string, or `-1` if there are no occurrences of the string in the line.
    `int` | `lnBack()` Returns the line number of this tracker's current back marker.
    `int` | `lnFront()` Returns the line number of this tracker's current front marker.
    `java.lang.String[]` | `segment(int lnlo, int collo, int lnhi, int colhi)` Given the pairs for the start and finish locations of a segment within this tracker's current viewing window, this method returns the specifed segment as an array of strings, one per line or partial line.

    - ### Methods inherited from class java.lang.Object

      `equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### ReaderLinesTracker

          public ReaderLinesTracker(java.io.Reader rdr)
                             throws java.io.IOException

      Constructs a new tracker for the given reader.
      Throws:
        `java.io.IOException`

    - #### ReaderLinesTracker

          public ReaderLinesTracker(java.io.File f)
                             throws java.io.IOException

      Constructs a new tracker for the given file.
      Throws:
        `java.io.IOException`

  - ### Method Detail

    - #### close

          public void close()

      Closes this tracker along with the reader that backs it.

    - #### lnBack

          public int lnBack()

      Returns the line number of this tracker's current back marker.

    - #### lnFront

          public int lnFront()

      Returns the line number of this tracker's current front marker.

    - #### advanceBack

          public void advanceBack(int lnlo,
                                  int collo)

      Advances this tracker's "back" marker to the location with the specified line and column numbers.

    - #### advanceFront

          public void advanceFront(int lnhi,
                                   int colhi)

      Advances this tracker's front marker to the location with the specified line and column numbers.

    - #### findInLine

          public int findInLine(int i,
                                java.lang.String s)

      Given the number of a line within this tracker's current viewing window, and a search string, this method returns the column number within the line of the specified line of (the first occurrence of) the specified string, or `-1` if there are no occurrences of the string in the line.

    - #### segment

          public java.lang.String[] segment(int lnlo,
                                            int collo,
                                            int lnhi,
                                            int colhi)

      Given the pairs for the start and finish locations of a segment within this tracker's current viewing window, this method returns the specifed segment as an array of strings, one per line or partial line.