Package org.apache.groovy.io
Class StringBuilderWriter
java.lang.Object
java.io.Writer
org.apache.groovy.io.StringBuilderWriter
- All Implemented Interfaces:
java.io.Closeable
,java.io.Flushable
,java.io.Serializable
,java.lang.Appendable
,java.lang.AutoCloseable
public class StringBuilderWriter
extends java.io.Writer
implements java.io.Serializable
Copied from https://github.com/apache/commons-io/blob/master/src/main/java/org/apache/commons/io/output/StringBuilderWriter.java
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 Thread
s then
java.io.StringWriter
should be used.
- Since:
- 2.0
- See Also:
- Serialized Form
-
Field Summary
Fields inherited from class java.io.Writer
lock
-
Constructor Summary
Constructors Constructor Description StringBuilderWriter()
Constructs a newStringBuilder
instance with default capacity.StringBuilderWriter(int capacity)
Constructs a newStringBuilder
instance with the specified capacity.StringBuilderWriter(java.lang.StringBuilder builder)
Constructs a new instance with the specifiedStringBuilder
. -
Method Summary
Modifier and Type Method Description java.io.Writer
append(char value)
Appends a single character to this Writer.java.io.Writer
append(java.lang.CharSequence value)
Appends a character sequence to this Writer.java.io.Writer
append(java.lang.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.java.lang.StringBuilder
getBuilder()
Returns the underlying builder.java.lang.String
toString()
ReturnsStringBuilder.toString()
.void
write(char[] value, int offset, int length)
Writes a portion of a character array to theStringBuilder
.void
write(java.lang.String value)
Writes a String to theStringBuilder
.Methods inherited from class java.io.Writer
nullWriter, write, write, write
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Constructor Details
-
StringBuilderWriter
public StringBuilderWriter()Constructs a newStringBuilder
instance with default capacity. -
StringBuilderWriter
public StringBuilderWriter(int capacity)Constructs a newStringBuilder
instance with the specified capacity.- Parameters:
capacity
- The initial capacity of the underlyingStringBuilder
-
StringBuilderWriter
public StringBuilderWriter(java.lang.StringBuilder builder)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
public java.io.Writer append(char value)Appends a single character to this Writer.- Specified by:
append
in interfacejava.lang.Appendable
- Overrides:
append
in classjava.io.Writer
- Parameters:
value
- The character to append- Returns:
- This writer instance
-
append
public java.io.Writer append(java.lang.CharSequence value)Appends a character sequence to this Writer.- Specified by:
append
in interfacejava.lang.Appendable
- Overrides:
append
in classjava.io.Writer
- Parameters:
value
- The character to append- Returns:
- This writer instance
-
append
public java.io.Writer append(java.lang.CharSequence value, int start, int end)Appends a portion of a character sequence to theStringBuilder
.- Specified by:
append
in interfacejava.lang.Appendable
- Overrides:
append
in classjava.io.Writer
- Parameters:
value
- The character to appendstart
- The index of the first characterend
- 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 interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Specified by:
close
in classjava.io.Writer
-
flush
public void flush()Flushing this writer has no effect.- Specified by:
flush
in interfacejava.io.Flushable
- Specified by:
flush
in classjava.io.Writer
-
write
public void write(java.lang.String value)Writes a String to theStringBuilder
.- Overrides:
write
in classjava.io.Writer
- Parameters:
value
- The value to write
-
write
public void write(char[] value, int offset, int length)Writes a portion of a character array to theStringBuilder
.- Specified by:
write
in classjava.io.Writer
- Parameters:
value
- The value to writeoffset
- The index of the first characterlength
- The number of characters to write
-
getBuilder
public java.lang.StringBuilder getBuilder()Returns the underlying builder.- Returns:
- The underlying builder
-
toString
public java.lang.String toString()ReturnsStringBuilder.toString()
.- Overrides:
toString
in classjava.lang.Object
- Returns:
- The contents of the String builder.
-