sdsu.io
Class SubstringCountReader

java.lang.Object
  |
  +--java.io.Reader
        |
        +--java.io.FilterReader
              |
              +--sdsu.io.StringReplaceReader
                    |
                    +--sdsu.io.SubstringCountReader

public class SubstringCountReader
extends StringReplaceReader

Given a substring (pattern), a replacement pattern and an input stream, this class will replace all occurances of the substring (pattern) with the replacement pattern in the inputstream and count the number of times the substring occured in the input stream. Any occurance of the seqeunce "_@N" in the replacement pattern will be replaced with number of occurances of the substring up to that point in the stream. Useful for adding page numbers, line numbers, etc. You can give multiple substring-replacement pattern pairs. Each pattern is counted separately.

Version:
0.5 31 August 1997
Author:
Roger Whitney (whitney@cs.sdsu.edu)

Field Summary
static java.lang.String COUNT_MARKER
          Sequence of characters indicating where the current count should appear in replacement pattern.
 
Constructor Summary
SubstringCountReader(java.io.InputStream in, java.lang.String substringToCount, java.lang.String newPattern, int initialCount)
          Create a SubstringCountReader on inputstream in where the pattern substringToCount is replaced with newPattern.
SubstringCountReader(java.io.Reader in, java.lang.String substringToCount, java.lang.String newPattern)
          Create a SubstringCountReader on Reader in where the pattern substringToCount is replaced with newPattern.
SubstringCountReader(java.io.Reader in, java.lang.String substringToCount, java.lang.String newPattern, int initialCount)
          Create a SubstringCountReader on Reader in where the pattern substringToCount is replaced with newPattern.
SubstringCountReader(java.lang.String in, java.lang.String substringToCount, java.lang.String newPattern, int initialCount)
          Create a SubstringCountReader on string in where the pattern substringToCount is replaced with newPattern.
 
Method Summary
 int getCount()
          Returns the current count of the number of times the pattern has occured.
 
Methods inherited from class sdsu.io.StringReplaceReader
contents, eof, read, read, replace
 
Methods inherited from class java.io.FilterReader
close, mark, markSupported, ready, reset, skip
 
Methods inherited from class java.io.Reader
read
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

COUNT_MARKER

public static final java.lang.String COUNT_MARKER
Sequence of characters indicating where the current count should appear in replacement pattern.
Constructor Detail

SubstringCountReader

public SubstringCountReader(java.lang.String in,
                            java.lang.String substringToCount,
                            java.lang.String newPattern,
                            int initialCount)
Create a SubstringCountReader on string in where the pattern substringToCount is replaced with newPattern. The counting of the pattern starts at value initialCount.

SubstringCountReader

public SubstringCountReader(java.io.InputStream in,
                            java.lang.String substringToCount,
                            java.lang.String newPattern,
                            int initialCount)
Create a SubstringCountReader on inputstream in where the pattern substringToCount is replaced with newPattern. The counting of the pattern starts at value initialCount.

SubstringCountReader

public SubstringCountReader(java.io.Reader in,
                            java.lang.String substringToCount,
                            java.lang.String newPattern,
                            int initialCount)
Create a SubstringCountReader on Reader in where the pattern substringToCount is replaced with newPattern. The counting of the pattern starts at value initialCount.

SubstringCountReader

public SubstringCountReader(java.io.Reader in,
                            java.lang.String substringToCount,
                            java.lang.String newPattern)
Create a SubstringCountReader on Reader in where the pattern substringToCount is replaced with newPattern. The counting of the pattern starts at value 1.
Method Detail

getCount

public int getCount()
Returns the current count of the number of times the pattern has occured.