|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Objectjava.io.Writer
org.tbull.util.StringBuilderWriter
public class StringBuilderWriter
Like StringWriter
, but completely unsynchronized.
While StringWriter
writes to a StringBuffer
, which is fully synchronized, this class writes
to a StringBuilder
, which is the unsynchronized version of StringBuffer
.
Use this if you don't need the sync or want to take care of that yourself.
You can use the StringBuilderWriter
and the underlying StringBuilder
interchangeably as long as
you don't do that concurrently from several threads (or you provide for appropriate locking). The writer will
always append to the current end of the buffer, regardless of what you do with the buffer. You get hold of the
underlying StringBuilder
either by constructing the writer with a self-supplied buffer, or by a call to
getBuilder()
.
For your convenience, this class also implements the CharSequence
interface, so that you can easily
examine the accumulated string data without constructing an intermediate String
object. Again, you can
combine this with interleaving write access as long as you take care of concurrency issues.
Ceterum censeo HTML in Javadoc is the dumbest idea ever.
CharSequenceReader
Constructor Summary | |
---|---|
StringBuilderWriter()
Creates a new stringbuilder writer. |
|
StringBuilderWriter(int initialCapacity)
Creates a new stringbuilder writer using the specified initial capacity. |
|
StringBuilderWriter(StringBuilder sb)
Creates a new stringbuilder writer using the supplied StringBuilder instead of creating a new one. |
Method Summary | |
---|---|
StringBuilderWriter |
append(char c)
|
StringBuilderWriter |
append(CharSequence csq)
|
StringBuilderWriter |
append(CharSequence csq,
int start,
int end)
|
char |
charAt(int index)
|
void |
close()
Does nothing. |
void |
flush()
Does nothing. |
StringBuilder |
getBuilder()
Returns the underlying StringBuilder . |
int |
length()
Returns the number of characters in the accumulated string data. |
CharSequence |
subSequence(int start,
int end)
|
String |
toString()
Returns the results of the operation so far. |
void |
write(char[] cbuf,
int off,
int len)
|
void |
write(int c)
|
void |
write(String str)
|
void |
write(String str,
int off,
int len)
|
Methods inherited from class java.io.Writer |
---|
write |
Methods inherited from class Object |
---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public StringBuilderWriter()
public StringBuilderWriter(int initialCapacity) throws IllegalArgumentException
initialCapacity
- The number of char
values that will fit into the buffer
before it is automatically expanded.
IllegalArgumentException
- If initialCapacity <= 0
.public StringBuilderWriter(StringBuilder sb)
StringBuilder
instead of creating a new one.
The buffer does not need to be empty. The writer always appends to the end of the buffer.
Method Detail |
---|
public StringBuilder getBuilder()
StringBuilder
.
This is a life object and still in use!
It is safe to continue using the writer afterwards, you can even intermix calls to the writer and to the
stringbuilder, as long as you don't do that concurrently from several threads. The writer will always
append to the current end of the stringbuilder.
public char charAt(int index) throws IndexOutOfBoundsException
charAt
in interface CharSequence
IndexOutOfBoundsException
public int length()
length
in interface CharSequence
public CharSequence subSequence(int start, int end) throws IndexOutOfBoundsException
subSequence
in interface CharSequence
IndexOutOfBoundsException
public String toString()
toString
in interface CharSequence
toString
in class Object
public StringBuilderWriter append(char c)
append
in interface Appendable
append
in class Writer
public StringBuilderWriter append(CharSequence csq, int start, int end) throws IndexOutOfBoundsException
append
in interface Appendable
append
in class Writer
IndexOutOfBoundsException
public StringBuilderWriter append(CharSequence csq)
append
in interface Appendable
append
in class Writer
public void write(int c)
write
in class Writer
public void write(char[] cbuf, int off, int len) throws IndexOutOfBoundsException
write
in class Writer
IndexOutOfBoundsException
public void write(String str)
write
in class Writer
public void write(String str, int off, int len) throws IndexOutOfBoundsException
write
in class Writer
IndexOutOfBoundsException
public void close()
close
in interface Closeable
close
in class Writer
public void flush()
flush
in interface Flushable
flush
in class Writer
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |