Package org.apache.directory.api.util
Class StringBuilderWriter
- java.lang.Object
-
- java.io.Writer
-
- org.apache.directory.api.util.StringBuilderWriter
-
- All Implemented Interfaces:
Closeable
,Flushable
,Appendable
,AutoCloseable
public class StringBuilderWriter extends Writer
Writer
implementation that outputs to aStringBuilder
.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 multipleThread
s thenjava.io.StringWriter
should be used.- Since:
- 2.0
- Version:
- $Id: StringBuilderWriter.java 1415850 2012-11-30 20:51:39Z ggregory $
-
-
Constructor Summary
Constructors Constructor Description StringBuilderWriter()
Construct a newStringBuilder
instance with default capacity.StringBuilderWriter(int capacity)
Construct a newStringBuilder
instance with the specified capacity.StringBuilderWriter(StringBuilder builder)
Construct a new instance with the specifiedStringBuilder
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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 theStringBuilder
.void
close()
Closing this writer has no effect.void
flush()
Flushing this writer has no effect.StringBuilder
getBuilder()
Return the underlying builder.String
toString()
ReturnsStringBuilder.toString()
.void
write(char[] value, int offset, int length)
Write a portion of a character array to theStringBuilder
.void
write(String value)
Write a String to theStringBuilder
.-
Methods inherited from class java.io.Writer
nullWriter, write, write, write
-
-
-
-
Constructor Detail
-
StringBuilderWriter
public StringBuilderWriter()
Construct a newStringBuilder
instance with default capacity.
-
StringBuilderWriter
public StringBuilderWriter(int capacity)
Construct a newStringBuilder
instance with the specified capacity.- Parameters:
capacity
- The initial capacity of the underlyingStringBuilder
-
StringBuilderWriter
public StringBuilderWriter(StringBuilder builder)
Construct a new instance with the specifiedStringBuilder
.- Parameters:
builder
- The String builder
-
-
Method Detail
-
append
public Writer append(char value)
Append 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
public Writer append(CharSequence value)
Append 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
public Writer append(CharSequence value, int start, int end)
Append 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
public void close()
Closing this writer has no effect.
-
flush
public void flush()
Flushing this writer has no effect.
-
write
public void write(String value)
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
public StringBuilder getBuilder()
Return the underlying builder.- Returns:
- The underlying builder
-
toString
public String toString()
ReturnsStringBuilder.toString()
.
-
-