Holger's
Java API

com.antelmann.io
Class ReplaceInputStream

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

public class ReplaceInputStream
extends InterceptInputStream
implements InterceptInputStream.Handler

This specialized stream replaces all occurrences 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.

Author:
Holger Antelmann

Nested Class Summary
 
Nested classes/interfaces inherited from class com.antelmann.io.InterceptInputStream
InterceptInputStream.Handler
 
Constructor Summary
ReplaceInputStream(InputStream in, byte[] searchPattern, byte[] replacePattern)
           
 
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 com.antelmann.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(InputStream in,
                          byte[] searchPattern,
                          byte[] replacePattern)
Method Detail

getReplacementCount

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


patternFound

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

Specified by:
patternFound in interface InterceptInputStream.Handler
Throws:
IOException


(c) Holger Antelmann since 2001- all rights reserved (contact: info@antelmann.com)
see www.antelmann.com/developer for further details and available downloads