net.jangaroo.jooc
Class SubstitutingWriter

java.lang.Object
  extended by java.io.Writer
      extended by java.io.FilterWriter
          extended by net.jangaroo.jooc.SubstitutingWriter
All Implemented Interfaces:
Closeable, Flushable, Appendable
Direct Known Subclasses:
JsStringLiteralWriter

public abstract class SubstitutingWriter
extends FilterWriter

An SubstitutingWriter is a FilterWriter that replaces each character in the output stream with the String obtained by calling the abstract method substitute on the characters.

Characters for which substitute returns null are output verbatim.

The implementation is fairly efficient in the number of calls to the various out.write methods.

Author:
Axel Wienberg

Field Summary
 
Fields inherited from class java.io.FilterWriter
out
 
Fields inherited from class java.io.Writer
lock
 
Constructor Summary
SubstitutingWriter(Writer out)
           
 
Method Summary
protected abstract  String substitute(char c)
          What should be printed instead of character c?
 void write(char[] cbuf, int off, int len)
          Write a portion of an array of characters, applying the substitution.
 void write(int c)
          Write a single character, applying the substitution.
 void write(String str, int off, int len)
          Write a portion of a string, applying the substitution.
protected  void writeReplacement(String replacement)
           
 
Methods inherited from class java.io.FilterWriter
close, flush
 
Methods inherited from class java.io.Writer
append, append, append, write, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SubstitutingWriter

public SubstitutingWriter(Writer out)
Method Detail

substitute

protected abstract String substitute(char c)
What should be printed instead of character c? This method is always called synchronized on out. Changes to the substitution function should therefore also be synchronized on out.

Parameters:
c - the character
Returns:
the string to be printed, or null for "no change", i.e. just c

writeReplacement

protected void writeReplacement(String replacement)
                         throws IOException
Throws:
IOException

write

public void write(int c)
           throws IOException
Write a single character, applying the substitution.

Overrides:
write in class FilterWriter
Throws:
IOException - If an I/O error occurs

write

public void write(char[] cbuf,
                  int off,
                  int len)
           throws IOException
Write a portion of an array of characters, applying the substitution.

Overrides:
write in class FilterWriter
Parameters:
cbuf - Buffer of characters to be written
off - Offset from which to start reading characters
len - Number of characters to be written
Throws:
IOException - If an I/O error occurs

write

public void write(String str,
                  int off,
                  int len)
           throws IOException
Write a portion of a string, applying the substitution.

Overrides:
write in class FilterWriter
Parameters:
str - String to be written
off - Offset from which to start reading characters
len - Number of characters to be written
Throws:
IOException - If an I/O error occurs


Copyright © 2002-2013 CoreMedia AG. All Rights Reserved.