org.mmbase.util
Class StringBuilderWriter

java.lang.Object
  extended by java.io.Writer
      extended by org.mmbase.util.StringBuilderWriter
All Implemented Interfaces:
Closeable, Flushable, Appendable

public class StringBuilderWriter
extends Writer

Oddly enough, Java does not provide this itself. Code is nearly identical to java.io.StringWriter. Code is also a near copy of StringBufferWriter.

Since:
MMBase-1.9
Version:
$Id: StringBuilderWriter.java 41036 2010-02-15 22:30:54Z michiel $
Author:
Michiel Meeuwissen
See Also:
StringWriter

Field Summary
protected  StringBuilder buffer
           
 
Fields inherited from class java.io.Writer
lock
 
Constructor Summary
StringBuilderWriter(StringBuilder buffer)
          Create a new StringBufferWriter
 
Method Summary
 void close()
          Closing a StringBuilderWriter has no effect.
 void flush()
          Flush the stream.
 StringBuilder getBuffer()
          Return the string buffer itself.
 String toString()
          Return the buffer's current value as a string.
 void write(char[] charArray, int offset, int length)
          Write a portion of an array of characters.
 void write(int c)
          Write a single character.
 void write(String str)
          Write a string.
 void write(String str, int offset, int length)
          Write a portion of a string.
 
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
 

Field Detail

buffer

protected StringBuilder buffer
Constructor Detail

StringBuilderWriter

public StringBuilderWriter(StringBuilder buffer)
Create a new StringBufferWriter

Parameters:
buffer - The StringBuffer to use
Throws:
NullPointerException - if buffer is null.
Method Detail

write

public void write(int c)
Write a single character.

Overrides:
write in class Writer

write

public void write(char[] charArray,
                  int offset,
                  int length)
Write a portion of an array of characters.

Specified by:
write in class Writer
Parameters:
charArray - Array of characters
offset - Offset from which to start writing characters
length - Number of characters to write

write

public void write(String str)
Write a string.

Overrides:
write in class Writer

write

public void write(String str,
                  int offset,
                  int length)
Write a portion of a string.

Overrides:
write in class Writer
Parameters:
str - String to be written
offset - Offset from which to start writing characters
length - Number of characters to write

toString

public String toString()
Return the buffer's current value as a string.

Overrides:
toString in class Object

getBuffer

public StringBuilder getBuffer()
Return the string buffer itself.

Returns:
StringBuilder holding the current buffer value.

flush

public void flush()
Flush the stream.

Specified by:
flush in interface Flushable
Specified by:
flush in class Writer

close

public void close()
           throws IOException
Closing a StringBuilderWriter has no effect. The methods in this class can be called after the stream has been closed without generating an IOException.

Specified by:
close in interface Closeable
Specified by:
close in class Writer
Throws:
IOException


MMBase 2.0-SNAPSHOT - null