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 bufferBufferedAppendable
public BufferedAppendable append(java.lang.CharSequence csq) throws java.io.IOException
BufferedAppendable
.append
in interface java.lang.Appendable
append
in class java.io.Writer
csq
- the character sequence to be appendedBufferedAppendable
java.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.Appendable
append
in class java.io.Writer
csq
- 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
subsequenceBufferedAppendable
java.io.IOException
- there was a problem appending to the underlying
Appendable
public BufferedAppendable append(char c) throws java.io.IOException
BufferedAppendable
.append
in interface java.lang.Appendable
append
in class java.io.Writer
c
- The character to appendBufferedAppendable
java.io.IOException
- there was a problem appending to the underlying
Appendable
public void write(int c) throws java.io.IOException
write
in class java.io.Writer
c
- 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.Writer
cbuf
- Array of characters to be writtenjava.io.IOException
- If an I/O error occursjava.lang.NullPointerException
- cbuf is null
public void write(char[] cbuf, int off, int len) throws java.io.IOException
write
in class java.io.Writer
cbuf
- 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 null
java.lang.IndexOutOfBoundsException
- off or len are out of boundspublic void write(java.lang.String str) throws java.io.IOException
write
in class java.io.Writer
str
- String to be writtenjava.io.IOException
- If an I/O error occursjava.lang.NullPointerException
- str is null
public void write(java.lang.String str, int off, int len) throws java.io.IOException
write
in class java.io.Writer
str
- 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 null
public void flush() throws java.io.IOException
BufferedAppendable
.flush
in interface java.io.Flushable
flush
in class java.io.Writer
java.io.IOException
- there was a problem appending to the underlying
Appendable
public void close() throws java.io.IOException
BufferedAppendable
.close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
close
in class java.io.Writer
java.io.IOException
- there was a problem appending to the underlying
Appendable