de.fhg.igd.io
Class StringSubstitutionInputStream

java.lang.Object
  extended by java.io.InputStream
      extended by de.fhg.igd.io.StringSubstitutionInputStream
All Implemented Interfaces:
Closeable

public class StringSubstitutionInputStream
extends InputStream

This is an InputStream wrapper that provides simple String substitution while reading from it.

After a substitution took place (by performing a look-ahead), the replacement String will not be processed again, which means that recursive substitution is not supported. To achieve this, two nested StringSubstitutionInputStream objects may be used.

Version:
$Id: StringSubstitutionInputStream.java 1913 2007-08-08 02:41:53Z jpeters $
Author:
Matthias Pressfreund

Field Summary
protected  StringBuffer back_
          A buffer for chars that need to be checked again
protected  boolean closed_
          This flag indicates that this stream has been closed
protected  StringBuffer done_
          A buffer for chars that have been already processed and therefore can be safely returned
protected  InputStream is_
          The wrapped input stream
private  Object lock_
          The local lock object
protected  StringBuffer read_
          A temporary read buffer
protected  Map subst_
          The substitution map
 
Constructor Summary
StringSubstitutionInputStream(InputStream is, Map subst)
          Creates a StringSubstitutionInputStream wrapping the given InputStream.
 
Method Summary
 int available()
           
 void close()
           
static void main(String[] args)
          Just for testing purposes...
protected  boolean maybeLater()
          Check whether or not the internal buffer may become a substitution candidate on further extension.
 int read()
           
 
Methods inherited from class java.io.InputStream
mark, markSupported, read, read, reset, skip
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

lock_

private Object lock_
The local lock object


is_

protected InputStream is_
The wrapped input stream


subst_

protected Map subst_
The substitution map


read_

protected StringBuffer read_
A temporary read buffer


back_

protected StringBuffer back_
A buffer for chars that need to be checked again


done_

protected StringBuffer done_
A buffer for chars that have been already processed and therefore can be safely returned


closed_

protected boolean closed_
This flag indicates that this stream has been closed

Constructor Detail

StringSubstitutionInputStream

public StringSubstitutionInputStream(InputStream is,
                                     Map subst)
Creates a StringSubstitutionInputStream wrapping the given InputStream.

Parameters:
is - The InputStream to be wrapped
subst - The map of substitutions, each entry contains a substitutable as key and the corresponding replacement as value
Throws:
NullPointerException - if the wrapped input stream is null or if the substitution map contains null keys/values
Method Detail

read

public int read()
         throws IOException
Specified by:
read in class InputStream
Throws:
IOException

maybeLater

protected boolean maybeLater()
Check whether or not the internal buffer may become a substitution candidate on further extension.

Returns:
true if the content of the internal buffer may fit to a substitution key later, if extended appropriately

available

public int available()
Overrides:
available in class InputStream

close

public void close()
           throws IOException
Specified by:
close in interface Closeable
Overrides:
close in class InputStream
Throws:
IOException

main

public static void main(String[] args)
Just for testing purposes...



Copyright © Fraunhofer Gesellschaft. All Rights Reserved.