org.compass.core.util
Class StringBuilderWriter

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

public class StringBuilderWriter
extends Writer

A Writer based on StringBuilder. Also alows for thread local reuse of StringBuilder by using: StringBuilderWriter.Cached.cached() in order to obtain the cached writer. Note, in such cases, the getBuilder() should be called and used (usually toString it) before another usage of the writer.

Author:
kimchy

Nested Class Summary
static class StringBuilderWriter.Cached
           
 
Field Summary
 
Fields inherited from class java.io.Writer
lock
 
Constructor Summary
StringBuilderWriter()
          Construct a new StringBuilder instance with default capacity.
StringBuilderWriter(int capacity)
          Construct a new StringBuilder instance with the specified capacity.
StringBuilderWriter(StringBuilder builder)
          Construct a new instance with the specified StringBuilder.
 
Method Summary
 Writer append(char value)
          Append a single character to this Writer.
 Writer append(CharSequence value)
          Append a character sequence to this Writer.
 Writer append(CharSequence value, int start, int end)
          Append a portion of a character sequence to the StringBuilder.
 void close()
          Closing this writer has no effect.
 void flush()
          Flushing this writer has no effect.
 StringBuilder getBuilder()
          Return the underlying builder.
 String toString()
          Returns StringBuilder.toString().
 void write(char[] value, int offset, int length)
          Write a portion of a character array to the StringBuilder.
 void write(String value)
          Write a String to the StringBuilder.
 
Methods inherited from class java.io.Writer
write, write, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

StringBuilderWriter

public StringBuilderWriter()
Construct a new StringBuilder instance with default capacity.


StringBuilderWriter

public StringBuilderWriter(int capacity)
Construct a new StringBuilder instance with the specified capacity.

Parameters:
capacity - The initial capacity of the underlying StringBuilder

StringBuilderWriter

public StringBuilderWriter(StringBuilder builder)
Construct a new instance with the specified StringBuilder.

Parameters:
builder - The String builder
Method Detail

append

public Writer append(char value)
Append a single character to this Writer.

Specified by:
append in interface Appendable
Overrides:
append in class Writer
Parameters:
value - The character to append
Returns:
This writer instance

append

public Writer append(CharSequence value)
Append a character sequence to this Writer.

Specified by:
append in interface Appendable
Overrides:
append in class Writer
Parameters:
value - The character to append
Returns:
This writer instance

append

public Writer append(CharSequence value,
                     int start,
                     int end)
Append a portion of a character sequence to the StringBuilder.

Specified by:
append in interface Appendable
Overrides:
append in class Writer
Parameters:
value - The character to append
start - The index of the first character
end - The index of the last character + 1
Returns:
This writer instance

close

public void close()
Closing this writer has no effect.

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

flush

public void flush()
Flushing this writer has no effect.

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

write

public void write(String value)
Write a String to the StringBuilder.

Overrides:
write in class Writer
Parameters:
value - The value to write

write

public void write(char[] value,
                  int offset,
                  int length)
Write a portion of a character array to the StringBuilder.

Specified by:
write in class Writer
Parameters:
value - The value to write
offset - The index of the first character
length - The number of characters to write

getBuilder

public StringBuilder getBuilder()
Return the underlying builder.

Returns:
The underlying builder

toString

public String toString()
Returns StringBuilder.toString().

Overrides:
toString in class Object
Returns:
The contents of the String builder.


Copyright (c) 2004-2009 The Compass Project.