org.jscience.io
Class ReplaceInputStream

java.lang.Object
  extended by java.io.InputStream
      extended by org.jscience.io.InterceptInputStream
          extended by org.jscience.io.ReplaceInputStream
All Implemented Interfaces:
java.io.Closeable, InterceptInputStream.Handler

public class ReplaceInputStream
extends InterceptInputStream
implements InterceptInputStream.Handler

This specialized stream replaces all occurences of a given byte pattern with another throughout the stream. Also, this class can easily be overwritten to e.g. only replace only the first or every second occurrence or the alike.


Nested Class Summary
 
Nested classes/interfaces inherited from class org.jscience.io.InterceptInputStream
InterceptInputStream.Handler
 
Constructor Summary
ReplaceInputStream(java.io.InputStream in, byte[] searchPattern, byte[] replacePattern)
          Creates a new ReplaceInputStream object.
 
Method Summary
 int getReplacementCount()
          returns the number of replacements so far
 void patternFound(InterceptInputStream stream, byte[] pattern)
          only used internally (implementing InterceptInputStream.Handler); skips the pattern length from the stream and inserts the replacementPattern
 
Methods inherited from class org.jscience.io.InterceptInputStream
addHandler, checkForMatch, close, insertBytes, markSupported, read, readSoFar, reset, skip
 
Methods inherited from class java.io.InputStream
available, mark, read, read
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ReplaceInputStream

public ReplaceInputStream(java.io.InputStream in,
                          byte[] searchPattern,
                          byte[] replacePattern)
Creates a new ReplaceInputStream object.

Parameters:
in - DOCUMENT ME!
searchPattern - DOCUMENT ME!
replacePattern - DOCUMENT ME!
Method Detail

getReplacementCount

public int getReplacementCount()
returns the number of replacements so far

Returns:
DOCUMENT ME!

patternFound

public void patternFound(InterceptInputStream stream,
                         byte[] pattern)
only used internally (implementing InterceptInputStream.Handler); skips the pattern length from the stream and inserts the replacementPattern

Specified by:
patternFound in interface InterceptInputStream.Handler
Parameters:
stream - DOCUMENT ME!
pattern - DOCUMENT ME!
Throws:
java.lang.Error - DOCUMENT ME!