Class StringBuilderWriter
java.lang.Object
java.io.Writer
org.zeroturnaround.zip.commons.StringBuilderWriter
- All Implemented Interfaces:
Closeable, Flushable, Serializable, Appendable, AutoCloseable
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.
- Since:
- 2.0
- Version:
- $Id: StringBuilderWriter.java 1304052 2012-03-22 20:55:29Z ggregory $
- See Also:
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionConstruct a newStringBuilderinstance with default capacity.StringBuilderWriter(int capacity) Construct a newStringBuilderinstance with the specified capacity.StringBuilderWriter(StringBuilder builder) Construct a new instance with the specifiedStringBuilder. -
Method Summary
Modifier and TypeMethodDescriptionappend(char value) Append a single character to this Writer.append(CharSequence value) Append a character sequence to this Writer.append(CharSequence value, int start, int end) Append a portion of a character sequence to theStringBuilder.voidclose()Closing this writer has no effect.voidflush()Flushing this writer has no effect.Return the underlying builder.toString()ReturnsStringBuilder.toString().voidwrite(char[] value, int offset, int length) Write a portion of a character array to theStringBuilder.voidWrite a String to theStringBuilder.Methods inherited from class Writer
nullWriter, write, write, write
-
Field Details
-
builder
-
-
Constructor Details
-
StringBuilderWriter
public StringBuilderWriter()Construct a newStringBuilderinstance with default capacity. -
StringBuilderWriter
public StringBuilderWriter(int capacity) Construct a newStringBuilderinstance with the specified capacity.- Parameters:
capacity- The initial capacity of the underlyingStringBuilder
-
StringBuilderWriter
Construct a new instance with the specifiedStringBuilder.- Parameters:
builder- The String builder
-
-
Method Details
-
append
Append a single character to this Writer.- Specified by:
appendin interfaceAppendable- Overrides:
appendin classWriter- Parameters:
value- The character to append- Returns:
- This writer instance
-
append
Append a character sequence to this Writer.- Specified by:
appendin interfaceAppendable- Overrides:
appendin classWriter- Parameters:
value- The character to append- Returns:
- This writer instance
-
append
Append a portion of a character sequence to theStringBuilder.- Specified by:
appendin interfaceAppendable- Overrides:
appendin 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
-
flush
-
write
Write a String to theStringBuilder. -
write
public void write(char[] value, int offset, int length) Write a portion of a character array to theStringBuilder. -
getBuilder
-
toString
ReturnsStringBuilder.toString().
-