sdsu.io
Class StringReplaceReader
java.lang.Object
|
+--java.io.Reader
|
+--java.io.FilterReader
|
+--sdsu.io.StringReplaceReader
- Direct Known Subclasses:
- SubstringCountReader
- public class StringReplaceReader
- extends java.io.FilterReader
- implements java.lang.Cloneable
Given a string pattern, a string replacementPattern and
an input stream, this
class will replace all occurances of pattern with
replacementPattern in the inputstream. You can give multiple
pattern-replacementPattern pairs. Multiple pairs are done in order
they are given.
If first pair is "cat"-"dog" and second pair is "dog"-"house", then
the result will
be all occurences of "cat" or "dog" will be replaced with "house".
- Since:
- version 0.5, Fixed error that occured when input was shorter
than the pattern
- Version:
- 0.6 21 August 1997
- Author:
- Roger Whitney
(whitney@cs.sdsu.edu)
Constructor Summary |
StringReplaceReader(java.io.InputStream in,
java.lang.String pattern,
java.lang.String replacementPattern)
Create an StringReplaceReader object that will replace all
occurrences of pattern with replacementPattern in the inputstream in. |
StringReplaceReader(java.io.Reader in,
java.lang.String pattern,
java.lang.String replacementPattern)
Create an StringReplaceReader object that will replace all
occurrences ofpattern with replacementPattern in the Reader in. |
StringReplaceReader(java.lang.String input,
java.lang.String pattern,
java.lang.String replacementPattern)
Create an StringReplaceReader object that will replace all
occurrences of pattern with replacementPattern in the string input. |
Method Summary |
java.lang.String |
contents()
Returns the entire contents of the input stream. |
boolean |
eof()
Determines if a previous ASCII I/O operation caught End Of File. |
int |
read()
Returns the next character in the inputstream with
string replacement done. |
int |
read(char[] buffer,
int offset,
int charsToRead)
Read characters into a portion of an array. |
void |
replace(java.lang.String pattern,
java.lang.String replacementPattern)
Adds another pattern-replacementPattern pair. |
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 |
StringReplaceReader
public StringReplaceReader(java.io.Reader in,
java.lang.String pattern,
java.lang.String replacementPattern)
- Create an StringReplaceReader object that will replace all
occurrences ofpattern with replacementPattern in the Reader in.
StringReplaceReader
public StringReplaceReader(java.io.InputStream in,
java.lang.String pattern,
java.lang.String replacementPattern)
- Create an StringReplaceReader object that will replace all
occurrences of pattern with replacementPattern in the inputstream in.
StringReplaceReader
public StringReplaceReader(java.lang.String input,
java.lang.String pattern,
java.lang.String replacementPattern)
- Create an StringReplaceReader object that will replace all
occurrences of pattern with replacementPattern in the string input.
contents
public java.lang.String contents()
throws java.io.IOException
- Returns the entire contents of the input stream.
replace
public void replace(java.lang.String pattern,
java.lang.String replacementPattern)
throws java.lang.OutOfMemoryError
- Adds another pattern-replacementPattern pair.
All occurrences of pattern will be replaced with replacementPattern.
- Throws:
- java.lang.OutOfMemoryError - if there is not enough memory to add new
pattern-replacementPattern pair
read
public int read(char[] buffer,
int offset,
int charsToRead)
throws java.io.IOException
- Read characters into a portion of an array.
This method will block until some input is available, an I/O error
occurs, or the end of the stream is reached.
- Returns:
- number of characters actually read, -1 if reah EOF on reading
first character
- Throws:
- java.io.IOException - if an I/O error occurs
- Overrides:
- read in class java.io.FilterReader
read
public int read()
throws java.io.IOException
- Returns the next character in the inputstream with
string replacement done.
- Throws:
- java.io.IOException - if error occurs reading io stream
- Overrides:
- read in class java.io.FilterReader
eof
public boolean eof()
- Determines if a previous ASCII I/O operation caught End Of File.
- Returns:
- true if end of file was reached.