org.jasig.portal.utils
Class SubstitutionWriter

java.lang.Object
  extended by java.io.Writer
      extended by org.jasig.portal.utils.SubstitutionWriter
All Implemented Interfaces:
java.io.Closeable, java.io.Flushable, java.lang.Appendable

public class SubstitutionWriter
extends java.io.Writer

A filter presenting a Writer that performs word substitution (search&replace) on the fly. 7/25/05 - UP-1180 - dmindler@rutgers.edu Modified to make use of optimized SubstitutionIntegerFilter

Version:
$Revision: 1.6.4.1 $
Author:
Peter Kharchenko

Field Summary
(package private)  SubstitutionIntegerFilter filter
           
 
Fields inherited from class java.io.Writer
lock
 
Constructor Summary
SubstitutionWriter(java.io.Writer out, char[] target, char[] substitute)
          Creates a new SubstitutionWriter instance.
SubstitutionWriter(java.io.Writer out, char[] target, char[] substitute, int bufferSize)
          Creates a new SubstitutionWriter instance.
 
Method Summary
 void close()
           
 void flush()
           
private static int[] getIntArrayFromCharArray(char[] c)
          A helper method to convert char array to int array.
static void main(java.lang.String[] args)
          A test self-test method for the class.
 void write(char[] cbuf, int off, int len)
           
 void write(int i)
           
 
Methods inherited from class java.io.Writer
append, append, append, append, append, append, write, write, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

filter

SubstitutionIntegerFilter filter
Constructor Detail

SubstitutionWriter

public SubstitutionWriter(java.io.Writer out,
                          char[] target,
                          char[] substitute,
                          int bufferSize)
Creates a new SubstitutionWriter instance.

Parameters:
out - a true Writer value where processed stream should be directed
target - a byte[] value of a target to be replaced
substitute - a byte[] value with which the target will be replaced
bufferSize - a size of the buffer

SubstitutionWriter

public SubstitutionWriter(java.io.Writer out,
                          char[] target,
                          char[] substitute)
Creates a new SubstitutionWriter instance.

Parameters:
out - a true Writer value where processed stream should be directed
target - a byte[] value of a target to be replaced
substitute - a byte[] value with which the target will be replaced
Method Detail

write

public void write(int i)
           throws java.io.IOException
Overrides:
write in class java.io.Writer
Throws:
java.io.IOException

flush

public void flush()
           throws java.io.IOException
Specified by:
flush in interface java.io.Flushable
Specified by:
flush in class java.io.Writer
Throws:
java.io.IOException

close

public void close()
           throws java.io.IOException
Specified by:
close in interface java.io.Closeable
Specified by:
close in class java.io.Writer
Throws:
java.io.IOException

write

public void write(char[] cbuf,
                  int off,
                  int len)
           throws java.io.IOException
Specified by:
write in class java.io.Writer
Throws:
java.io.IOException

getIntArrayFromCharArray

private static int[] getIntArrayFromCharArray(char[] c)
A helper method to convert char array to int array. I am sure there's a way to cast it correctly, but I don't want to take my chances :)

Parameters:
c - a char[] value
Returns:
an int[] value

main

public static void main(java.lang.String[] args)
A test self-test method for the class.