Closeable, Flushable, Serializable, Appendable, AutoCloseablepublic class StringBuilderWriter extends Writer implements Serializable
Writer implementation that outputs to a StringBuilder.
NOTE: This implementation, as an alternative to
java.io.StringWriter, provides an un-synchronized
(i.e. for use in a single thread) implementation for better performance.
For safe usage with multiple Threads then
java.io.StringWriter should be used.
| Constructor | Description |
|---|---|
StringBuilderWriter() |
Constructs a new
StringBuilder instance with default capacity. |
StringBuilderWriter(int capacity) |
Constructs a new
StringBuilder instance with the specified capacity. |
StringBuilderWriter(StringBuilder builder) |
Constructs a new instance with the specified
StringBuilder. |
| Modifier and Type | Method | Description |
|---|---|---|
Writer |
append(char value) |
Appends a single character to this Writer.
|
Writer |
append(CharSequence value) |
Appends a character sequence to this Writer.
|
Writer |
append(CharSequence value,
int start,
int end) |
Appends 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() |
Returns the underlying builder.
|
String |
toString() |
Returns
StringBuilder.toString(). |
void |
write(char[] value,
int offset,
int length) |
Writes a portion of a character array to the
StringBuilder. |
void |
write(String value) |
Writes a String to the
StringBuilder. |
public StringBuilderWriter()
StringBuilder instance with default capacity.public StringBuilderWriter(int capacity)
StringBuilder instance with the specified capacity.capacity - The initial capacity of the underlying StringBuilderpublic StringBuilderWriter(StringBuilder builder)
StringBuilder.
If builder is null a new instance with default capacity will be created.
builder - The String builder. May be null.public Writer append(char value)
append in interface Appendableappend in class Writervalue - The character to appendpublic Writer append(CharSequence value)
append in interface Appendableappend in class Writervalue - The character to appendpublic Writer append(CharSequence value, int start, int end)
StringBuilder.append in interface Appendableappend in class Writervalue - The character to appendstart - The index of the first characterend - The index of the last character + 1public void close()
public void flush()
public void write(String value)
StringBuilder.public void write(char[] value,
int offset,
int length)
StringBuilder.public StringBuilder getBuilder()
public String toString()
StringBuilder.toString().Copyright © 1999-2018. All Rights Reserved.
Apache Logging, Apache Log4j, Log4j, Apache, the Apache feather logo, the Apache Logging project logo, and the Apache Log4j logo are trademarks of The Apache Software Foundation.