Top Description Fields Constructors Methods
org.glassfish.jaxb.runtime.util

public Class StringBuilderWriter

extends Writer
Class Inheritance
Imports
java.io.IOException, .Writer

A character stream that collects its output in a string builder, which can then be used to construct a string.

Closing a StringBuilderWriter has no effect. The methods in this class can be called after the stream has been closed without generating an IOException.

This class is an alternative of JDK java.io.StringWriter. It is backed up by StringBuilder for better performance without the need of synchronization of a StringBuffer.

Instances of StringBuilderWriter are not safe for use by multiple threads. If such synchronization is required then it is recommended that java.io.StringWriter be used.

Author
Laurent Schoelens
Since
4.0.7

Field Summary

Modifier and TypeField and Description
private final StringBuilder
Inherited from java.io.Writer:
lock

Constructor Summary

AccessConstructor and Description
public
StringBuilderWriter()

Create a new string-builder writer using the default initial string-builder size.

public
StringBuilderWriter(int
The number of char values that will fit into this StringBuilder before it is automatically expanded
initialSize
)

Create a new string-builder writer using the specified initial string-builder size.

public
StringBuilderWriter(StringBuilder
The string-builder to use. could be null and default-sized string-builder will be created
sb
)

Create a new string-builder writer using the specified string-builder.

Method Summary

Modifier and TypeMethod and Description
public void
close()

Implements abstract java.io.Writer.close.

Implements java.io.Closeable.close.

Closing a StringBuilderWriter has no effect.

public void
flush()

Implements abstract java.io.Writer.flush.

Implements java.io.Flushable.flush.

Flush the stream.

public StringBuilder

Returns:

StringBuilder holding the current string-builder value.
getBuilder
()

Return the string builder itself.

public String
toString()

Overrides java.lang.Object.toString.

Return the buffer's current value as a string.

public void
write(int
int specifying a character to be written
c
)

Overrides java.io.Writer.write.

Writes a single character.

public void
write(char[]
Array of characters
cbuf
,
int
Offset from which to start writing characters
off
,
int
Number of characters to write
len
)

Implements abstract java.io.Writer.write.

Writes a portion of an array of characters.

public void
write(String
String to be written
str
)

Overrides java.io.Writer.write.

Writes a string.

public void
write(String
A String
str
,
int
Offset from which to start writing characters
off
,
int
Number of characters to write
len
)

Overrides java.io.Writer.write.

Writes a portion of a string.

Inherited from java.io.Writer:
appendappendappendnullWriterwrite

Field Detail

sbback to summary
private final StringBuilder sb

Constructor Detail

StringBuilderWriterback to summary
public StringBuilderWriter()

Create a new string-builder writer using the default initial string-builder size.

StringBuilderWriterback to summary
public StringBuilderWriter(int initialSize)

Create a new string-builder writer using the specified initial string-builder size.

Parameters
initialSize:int

The number of char values that will fit into this StringBuilder before it is automatically expanded

Exceptions
IllegalArgumentException:
If initialSize is negative
StringBuilderWriterback to summary
public StringBuilderWriter(StringBuilder sb)

Create a new string-builder writer using the specified string-builder.

Parameters
sb:StringBuilder

The string-builder to use. could be null and default-sized string-builder will be created

Method Detail

closeback to summary
public void close()

Implements abstract java.io.Writer.close.

Implements java.io.Closeable.close.

Closing a StringBuilderWriter has no effect. The methods in this class can be called after the stream has been closed without generating an IOException.

Annotations
@Override
flushback to summary
public void flush()

Implements abstract java.io.Writer.flush.

Implements java.io.Flushable.flush.

Flush the stream.

The flush method of StringBuilderWriter does nothing.

Annotations
@Override
getBuilderback to summary
public StringBuilder getBuilder()

Return the string builder itself.

Returns:StringBuilder

StringBuilder holding the current string-builder value.

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Return the buffer's current value as a string.

writeback to summary
public void write(int c) throws IOException

Overrides java.io.Writer.write.

Writes a single character.

Parameters
c:int

int specifying a character to be written

Annotations
@Override
Exceptions
IOException:
If an I/O error occurs
writeback to summary
public void write(char[] cbuf, int off, int len) throws IOException

Implements abstract java.io.Writer.write.

Writes a portion of an array of characters.

Parameters
cbuf:char[]

Array of characters

off:int

Offset from which to start writing characters

len:int

Number of characters to write

Annotations
@Override
Exceptions
IOException:
If an I/O error occurs
writeback to summary
public void write(String str) throws IOException

Overrides java.io.Writer.write.

Writes a string.

Parameters
str:String

String to be written

Annotations
@Override
Exceptions
IOException:
If an I/O error occurs
writeback to summary
public void write(String str, int off, int len) throws IOException

Overrides java.io.Writer.write.

Writes a portion of a string.

Parameters
str:String

A String

off:int

Offset from which to start writing characters

len:int

Number of characters to write

Annotations
@Override
Exceptions
IOException:
If an I/O error occurs