Package net.jangaroo.jooc
Class SubstitutingWriter
- java.lang.Object
-
- java.io.Writer
-
- java.io.FilterWriter
-
- net.jangaroo.jooc.SubstitutingWriter
-
- All Implemented Interfaces:
Closeable,Flushable,Appendable,AutoCloseable
- 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
-
-
Constructor Summary
Constructors Constructor Description SubstitutingWriter(Writer out)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract Stringsubstitute(char c)What should be printed instead of characterc? This method is always called synchronized onout.voidwrite(char[] cbuf, int off, int len)Write a portion of an array of characters, applying the substitution.voidwrite(int c)Write a single character, applying the substitution.voidwrite(String str, int off, int len)Write a portion of a string, applying the substitution.protected voidwriteReplacement(String replacement)-
Methods inherited from class java.io.FilterWriter
close, flush
-
-
-
-
Constructor Detail
-
SubstitutingWriter
public SubstitutingWriter(Writer out)
-
-
Method Detail
-
substitute
protected abstract String substitute(char c)
What should be printed instead of characterc? This method is always called synchronized onout. Changes to the substitution function should therefore also be synchronized onout.- 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 IOExceptionWrite a single character, applying the substitution.- Overrides:
writein classFilterWriter- Throws:
IOException- If an I/O error occurs
-
write
public void write(char[] cbuf, int off, int len) throws IOExceptionWrite a portion of an array of characters, applying the substitution.- Overrides:
writein classFilterWriter- Parameters:
cbuf- Buffer of characters to be writtenoff- Offset from which to start reading characterslen- 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:
writein classFilterWriter- Parameters:
str- String to be writtenoff- Offset from which to start reading characterslen- Number of characters to be written- Throws:
IOException- If an I/O error occurs
-
-