- java.lang.Object
-
- java.io.Writer
-
- org.glassfish.jaxb.runtime.util.StringBuilderWriter
-
- All Implemented Interfaces:
Closeable,Flushable,Appendable,AutoCloseable
public class StringBuilderWriter extends Writer
A character stream that collects its output in a string builder, which can then be used to construct a string.Closing a
StringBuilderWriterhas no effect. The methods in this class can be called after the stream has been closed without generating anIOException.This class is an alternative of JDK
java.io.StringWriter. It is backed up byStringBuilderfor better performance without the need of synchronization of aStringBuffer.Instances of
StringBuilderWriterare not safe for use by multiple threads. If such synchronization is required then it is recommended thatStringWriterbe used.- Since:
- 4.0.7
- Author:
- Laurent Schoelens
-
-
Constructor Summary
Constructors Constructor Description StringBuilderWriter()Create a new string-builder writer using the default initial string-builder size.StringBuilderWriter(int initialSize)Create a new string-builder writer using the specified initial string-builder size.StringBuilderWriter(StringBuilder sb)Create a new string-builder writer using the specified string-builder.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Closing aStringBuilderWriterhas no effect.voidflush()Flush the stream.StringBuildergetBuilder()Return the string builder itself.StringtoString()Return the buffer's current value as a string.voidwrite(char[] cbuf, int off, int len)Writes a portion of an array of characters.voidwrite(int c)Writes a single character.voidwrite(String str)Writes a string.voidwrite(String str, int off, int len)Writes a portion of a string.
-
-
-
Constructor Detail
-
StringBuilderWriter
public StringBuilderWriter()
Create a new string-builder writer using the default initial string-builder size.
-
StringBuilderWriter
public StringBuilderWriter(int initialSize)
Create a new string-builder writer using the specified initial string-builder size.- Parameters:
initialSize- The number ofcharvalues that will fit into this StringBuilder before it is automatically expanded- Throws:
IllegalArgumentException- IfinitialSizeis negative
-
StringBuilderWriter
public StringBuilderWriter(StringBuilder sb)
Create a new string-builder writer using the specified string-builder.- Parameters:
sb- The string-builder to use. could be null and default-sized string-builder will be created
-
-
Method Detail
-
getBuilder
public StringBuilder getBuilder()
Return the string builder itself.- Returns:
- StringBuilder holding the current string-builder value.
-
write
public void write(int c) throws IOExceptionWrites a single character.- Overrides:
writein classWriter- Parameters:
c- int specifying a character to be written- Throws:
IOException- If an I/O error occurs
-
write
public void write(char[] cbuf, int off, int len) throws IOExceptionWrites a portion of an array of characters.- Specified by:
writein classWriter- Parameters:
cbuf- Array of charactersoff- Offset from which to start writing characterslen- Number of characters to write- Throws:
IOException- If an I/O error occurs
-
write
public void write(String str) throws IOException
Writes a string.- Overrides:
writein classWriter- Parameters:
str- String to be written- Throws:
IOException- If an I/O error occurs
-
write
public void write(String str, int off, int len) throws IOException
Writes a portion of a string.- Overrides:
writein classWriter- Parameters:
str- A Stringoff- Offset from which to start writing characterslen- Number of characters to write- Throws:
IOException- If an I/O error occurs
-
toString
public String toString()
Return the buffer's current value as a string.
-
flush
public void flush()
Flush the stream.The
flushmethod ofStringBuilderWriterdoes nothing.
-
close
public void close()
Closing aStringBuilderWriterhas no effect. The methods in this class can be called after the stream has been closed without generating anIOException.
-
-