JSPTemplates

org.tp23.jasper.runtime
Class ClearableStringWriter

java.lang.Object
  |
  +--java.io.Writer
        |
        +--java.io.StringWriter
              |
              +--org.tp23.jasper.runtime.ClearableStringWriter

public class ClearableStringWriter
extends java.io.StringWriter

This has been cribbed of Java StringWriter but allows the StringBufferinside to be emptied. This means that if someone wants to forward the destination we can clear the contents so anyone holding a reference to the origional writer will not have the string content that is meant to be discarded

Author:
Paul Hinds

Fields inherited from class java.io.Writer
lock
 
Constructor Summary
ClearableStringWriter()
          Create a new string writer, using the default initial string-buffer size.
ClearableStringWriter(int initialSize)
          Create a new string writer, using the specified initial string-buffer size.
 
Method Summary
 void clear()
           
 void close()
          Close the stream.
 void flush()
          Flush the stream.
 java.lang.StringBuffer getBuffer()
          Return the string buffer itself.
 int getRemaining()
           
 java.lang.String toString()
          Return the buffer's current value as a string.
 void write(char[] cbuf, int off, int len)
          Write a portion of an array of characters.
 void write(int c)
          Write a single character.
 void write(java.lang.String str)
          Write a string.
 void write(java.lang.String str, int off, int len)
          Write a portion of a string.
 
Methods inherited from class java.io.Writer
write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ClearableStringWriter

public ClearableStringWriter()
Create a new string writer, using the default initial string-buffer size.

ClearableStringWriter

public ClearableStringWriter(int initialSize)
Create a new string writer, using the specified initial string-buffer size.
Parameters:
initialSize - an int specifying the initial size of the buffer.
Method Detail

write

public void write(int c)
Write a single character.
Overrides:
write in class java.io.StringWriter

write

public void write(char[] cbuf,
                  int off,
                  int len)
Write a portion of an array of characters.
Overrides:
write in class java.io.StringWriter
Parameters:
cbuf - Array of characters
off - Offset from which to start writing characters
len - Number of characters to write

write

public void write(java.lang.String str)
Write a string.
Overrides:
write in class java.io.StringWriter

write

public void write(java.lang.String str,
                  int off,
                  int len)
Write a portion of a string.
Overrides:
write in class java.io.StringWriter
Parameters:
str - String to be written
off - Offset from which to start writing characters
len - Number of characters to write

toString

public java.lang.String toString()
Return the buffer's current value as a string.
Overrides:
toString in class java.io.StringWriter

getBuffer

public java.lang.StringBuffer getBuffer()
Return the string buffer itself.
Overrides:
getBuffer in class java.io.StringWriter
Returns:
StringBuffer holding the current buffer value.

flush

public void flush()
Flush the stream.
Overrides:
flush in class java.io.StringWriter

close

public void close()
           throws java.io.IOException
Close the stream. This method does not release the buffer, since its contents might still be required.
Overrides:
close in class java.io.StringWriter

clear

public void clear()

getRemaining

public int getRemaining()
Returns:
the number of bytes unused in the buffer

JSPTemplates