Package org.apache.commons.io.output
Class StringBuilderWriter
java.lang.Object
java.io.Writer
org.apache.commons.io.output.StringBuilderWriter
- All Implemented Interfaces:
Closeable
,Flushable
,Serializable
,Appendable
,AutoCloseable
Writer
implementation that outputs to a StringBuilder
.
NOTE: This implementation, as an alternative to StringWriter
, provides an un-synchronized implementation for better
performance for use in a single thread. For safe usage with multiple Thread
s, a StringWriter
should be used.
Deprecating Serialization
Serialization is deprecated and will be removed in 3.0.
- Since:
- 2.0
- See Also:
-
Field Summary
-
Constructor Summary
ConstructorDescriptionConstructs a newStringBuilder
instance with default capacity.StringBuilderWriter
(int capacity) Constructs a newStringBuilder
instance with the specified capacity.StringBuilderWriter
(StringBuilder builder) Constructs a new instance with the specifiedStringBuilder
. -
Method Summary
Modifier and TypeMethodDescriptionappend
(char value) Appends a single character to this Writer.append
(CharSequence value) Appends a character sequence to this Writer.append
(CharSequence value, int start, int end) Appends a portion of a character sequence to theStringBuilder
.void
close()
Closing this writer has no effect.void
flush()
Flushing this writer has no effect.Gets the underlying builder.toString()
ReturnsStringBuilder.toString()
.void
write
(char[] value, int offset, int length) Writes a portion of a character array to theStringBuilder
.void
Writes a String to theStringBuilder
.
-
Constructor Details
-
StringBuilderWriter
public StringBuilderWriter()Constructs a newStringBuilder
instance with default capacity. -
StringBuilderWriter
Constructs a newStringBuilder
instance with the specified capacity.- Parameters:
capacity
- The initial capacity of the underlyingStringBuilder
-
StringBuilderWriter
Constructs a new instance with the specifiedStringBuilder
.If
builder
is null a new instance with default capacity will be created.- Parameters:
builder
- The String builder. May be null.
-
-
Method Details
-
append
Appends a single character to this Writer.- Specified by:
append
in interfaceAppendable
- Overrides:
append
in classWriter
- Parameters:
value
- The character to append- Returns:
- This writer instance
-
append
Appends a character sequence to this Writer.- Specified by:
append
in interfaceAppendable
- Overrides:
append
in classWriter
- Parameters:
value
- The character to append- Returns:
- This writer instance
-
append
Appends a portion of a character sequence to theStringBuilder
.- Specified by:
append
in interfaceAppendable
- Overrides:
append
in classWriter
- Parameters:
value
- The character to appendstart
- The index of the first characterend
- The index of the last character + 1- Returns:
- This writer instance
-
close
Closing this writer has no effect. -
flush
Flushing this writer has no effect. -
getBuilder
Gets the underlying builder.- Returns:
- The underlying builder
-
toString
ReturnsStringBuilder.toString()
. -
write
Writes a portion of a character array to theStringBuilder
. -
write
Writes a String to theStringBuilder
.
-