pulse - the web application framework Get pulse at SourceForge.net. Fast, secure and Free Open Source software downloads Ohloh project report for pulse-java

org.torweg.pulse.util.io
Class FastStringWriter

java.lang.Object
  extended by java.io.Writer
      extended by org.torweg.pulse.util.io.FastStringWriter
All Implemented Interfaces:
java.io.Closeable, java.io.Flushable, java.lang.Appendable

public final class FastStringWriter
extends java.io.Writer

A not thread-safe replacement for StringWriter which internally uses a StringBuilder as the buffer.

Version:
$Revision$
Author:
Thomas Weber
See Also:
FastByteArrayOutputStream

Field Summary
 
Fields inherited from class java.io.Writer
lock
 
Constructor Summary
FastStringWriter()
          creates a new FastStringWriter, using the default initial size for the underlying StringBuilder.
FastStringWriter(int size)
          creates a new FastStringWriter, using the specified initial size for the underlying StringBuilder.
FastStringWriter(int size, java.io.Writer target)
          creates a new FastStringWriter, using the specified initial size for the underlying StringBuilder writing through to the given Writer.
FastStringWriter(java.io.Writer target)
          creates a new FastStringWriter, using the default initial size for the underlying StringBuilder writing through to the given Writer.
 
Method Summary
 void close()
          closes the optional write-through Writer.
 void flush()
          flushes the optional write-through Writer.
 java.lang.StringBuilder getStringBuilder()
          returns the underlying StringBuilder.
 java.lang.String toString()
          returns the contents of the Writer as a String.
 void write(char[] cbuf, int off, int len)
          
 void write(int c)
          
 void write(java.lang.String str)
          
 void write(java.lang.String str, int off, int len)
          
 
Methods inherited from class java.io.Writer
append, append, append, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

FastStringWriter

public FastStringWriter()
creates a new FastStringWriter, using the default initial size for the underlying StringBuilder.


FastStringWriter

public FastStringWriter(java.io.Writer target)
creates a new FastStringWriter, using the default initial size for the underlying StringBuilder writing through to the given Writer.

Parameters:
target - the writer to write through

FastStringWriter

public FastStringWriter(int size)
creates a new FastStringWriter, using the specified initial size for the underlying StringBuilder.

Parameters:
size - the initial size for the StringBuilder.

FastStringWriter

public FastStringWriter(int size,
                        java.io.Writer target)
creates a new FastStringWriter, using the specified initial size for the underlying StringBuilder writing through to the given Writer.

Parameters:
size - the initial size for the StringBuilder.
target - the writer to write through
Method Detail

write

public void write(int c)

Overrides:
write in class java.io.Writer
Throws:
WriteThroughException - on I/O errors in the optional write-through Writer

write

public void write(char[] cbuf,
                  int off,
                  int len)

Specified by:
write in class java.io.Writer
Throws:
WriteThroughException - on I/O errors in the optional write-through Writer

write

public void write(java.lang.String str)

Overrides:
write in class java.io.Writer
Throws:
WriteThroughException - on I/O errors in the optional write-through Writer

write

public void write(java.lang.String str,
                  int off,
                  int len)

Overrides:
write in class java.io.Writer
Throws:
WriteThroughException - on I/O errors in the optional write-through Writer

toString

public java.lang.String toString()
returns the contents of the Writer as a String.

Overrides:
toString in class java.lang.Object
Returns:
the contents as a string

getStringBuilder

public java.lang.StringBuilder getStringBuilder()
returns the underlying StringBuilder.

Returns:
the underlying StringBuilder

flush

public void flush()
flushes the optional write-through Writer.

Specified by:
flush in interface java.io.Flushable
Specified by:
flush in class java.io.Writer
Throws:
WriteThroughException - on I/O errors in the optional write-through Writer

close

public void close()
closes the optional write-through Writer.

Specified by:
close in interface java.io.Closeable
Specified by:
close in class java.io.Writer
Throws:
WriteThroughException - on I/O errors in the optional write-through Writer