public final class BufferedAppendable
extends java.io.Writer
Appendable, without the synchronization of
java.io.BufferedWriter. This means that all operations on a
BufferedAppendable object must be performed synchronously.
In addition, the Appendable to be buffered is supplied using the
with(Appendable) method, rather than at construction time. This
allows the buffer to be reused for several different operations requiring
buffering.
Uses java.nio.CharBuffer.allocate() to create the backing buffer.
Does not propagate the flush() or close() methods
to the wrapped Appendable.
| Modifier and Type | Field and Description |
|---|---|
static int |
DEFAULT_BUFFER_SIZE
The default buffer size of 1024 characters, if none is specified.
|
| Constructor and Description |
|---|
BufferedAppendable()
Buffer a given
Appendable with the default buffer size. |
BufferedAppendable(int buffSize)
Buffer a given
Appendable with the given buffer size. |
| Modifier and Type | Method and Description |
|---|---|
BufferedAppendable |
append(char c)
Appends the specified character to this
BufferedAppendable. |
BufferedAppendable |
append(java.lang.CharSequence csq)
Appends the specified character sequence to this
BufferedAppendable. |
BufferedAppendable |
append(java.lang.CharSequence csq,
int start,
int end)
Appends a subsequence of the specified character sequence to this
BufferedAppendable. |
void |
close()
Flush and close the buffer of this
BufferedAppendable. |
void |
flush()
Flush the buffer of this
BufferedAppendable. |
BufferedAppendable |
with(java.lang.Appendable newAppendable)
Reset this buffered appendable, setting it to buffer the given
appendable.
|
void |
write(char[] cbuf)
Writes an array of characters.
|
void |
write(char[] cbuf,
int off,
int len)
Writes a portion of an array of characters.
|
void |
write(int c)
Writes a single character.
|
void |
write(java.lang.String str)
Writes a string.
|
void |
write(java.lang.String str,
int off,
int len)
Writes a portion of a string.
|
public static final int DEFAULT_BUFFER_SIZE
public BufferedAppendable()
Appendable with the default buffer size.public BufferedAppendable(int buffSize)
Appendable with the given buffer size.
The size must be at least 16.buffSize - the buffer size, must be >= 16java.lang.NullPointerException - the supplied Appendable is nullpublic BufferedAppendable with(java.lang.Appendable newAppendable)
Appendable first.
This resets the state of the buffered reader to the open state
if the new appendable is non-null, otherwise resets the state to
closed.
newAppendable - the new Appendable to bufferBufferedAppendablepublic BufferedAppendable append(java.lang.CharSequence csq) throws java.io.IOException
BufferedAppendable.append in interface java.lang.Appendableappend in class java.io.Writercsq - the character sequence to be appendedBufferedAppendablejava.io.IOException - there was a problem appending to the underlying
appendablepublic BufferedAppendable append(java.lang.CharSequence csq, int start, int end) throws java.io.IOException
BufferedAppendable.append in interface java.lang.Appendableappend in class java.io.Writercsq - The character sequence from which a subsequence will be
appended.start - The index of the first character in the subsequenceend - The index of the character following the last character in the
subsequenceBufferedAppendablejava.io.IOException - there was a problem appending to the underlying
Appendablepublic BufferedAppendable append(char c) throws java.io.IOException
BufferedAppendable.append in interface java.lang.Appendableappend in class java.io.Writerc - The character to appendBufferedAppendablejava.io.IOException - there was a problem appending to the underlying
Appendablepublic void write(int c)
throws java.io.IOException
write in class java.io.Writerc - int specifying a character to be writtenjava.io.IOException - If an I/O error occurspublic void write(char[] cbuf)
throws java.io.IOException
write in class java.io.Writercbuf - Array of characters to be writtenjava.io.IOException - If an I/O error occursjava.lang.NullPointerException - cbuf is nullpublic void write(char[] cbuf,
int off,
int len)
throws java.io.IOException
write in class java.io.Writercbuf - Array of charactersoff - Offset from which to start writing characterslen - Number of characters to writejava.io.IOException - If an I/O error occursjava.lang.NullPointerException - cbuf is nulljava.lang.IndexOutOfBoundsException - off or len are out of boundspublic void write(java.lang.String str)
throws java.io.IOException
write in class java.io.Writerstr - String to be writtenjava.io.IOException - If an I/O error occursjava.lang.NullPointerException - str is nullpublic void write(java.lang.String str,
int off,
int len)
throws java.io.IOException
write in class java.io.Writerstr - A Stringoff - Offset from which to start writing characterslen - Number of characters to writejava.lang.IndexOutOfBoundsException - If off is negative, or len is negative,
or off+len is negative or greater than the length
of the given stringjava.io.IOException - If an I/O error occursjava.lang.NullPointerException - str is nullpublic void flush()
throws java.io.IOException
BufferedAppendable.flush in interface java.io.Flushableflush in class java.io.Writerjava.io.IOException - there was a problem appending to the underlying
Appendablepublic void close()
throws java.io.IOException
BufferedAppendable.close in interface java.io.Closeableclose in interface java.lang.AutoCloseableclose in class java.io.Writerjava.io.IOException - there was a problem appending to the underlying
Appendable