public class EncodedWriter
extends java.io.Writer
| Modifier and Type | Field and Description |
|---|---|
private java.nio.CharBuffer |
_buffer
Where encoded output is buffered before sending on to the output writer.
|
private Encoder |
_encoder
The encoder used to encode input to the output writer.
|
private boolean |
_hasLeftOver
Some encoders require more input or an explicit end-of-input flag before they will process the remaining characters of an
input buffer.
|
private java.nio.CharBuffer |
_leftOverBuffer
See comment on _hasLeftOver.
|
private java.io.Writer |
_out
The wrapped writer.
|
(package private) static int |
BUFFER_SIZE
Buffer size to allocate.
|
(package private) static int |
LEFT_OVER_BUFFER
Buffer to use for handling characters remaining in the input buffer after an encode.
|
| Constructor and Description |
|---|
EncodedWriter(java.io.Writer out,
Encoder encoder)
Creates an EncodedWriter that uses the specified encoder to encode all input before sending it to the wrapped writer.
|
EncodedWriter(java.io.Writer out,
java.lang.String contextName)
Creates an EncodedWriter that uses the specified encoder to encode all input before sending it to the wrapped writer.
|
| Modifier and Type | Method and Description |
|---|---|
void |
close() |
void |
flush() |
private void |
flushBufferToWriter()
Flushes the contents of the buffer to the writer and resets the buffer to make room for more input.
|
private void |
flushLeftOver(java.nio.CharBuffer input)
Flushes the left-over buffer.
|
void |
write(char[] cbuf,
int off,
int len) |
static final int BUFFER_SIZE
static final int LEFT_OVER_BUFFER
private java.io.Writer _out
private Encoder _encoder
private java.nio.CharBuffer _buffer
private boolean _hasLeftOver
_hasLeftOver boolean is a flag used to indicate that there are left over characters in the buffer.private java.nio.CharBuffer _leftOverBuffer
public EncodedWriter(java.io.Writer out,
Encoder encoder)
out - the target for all writesencoder - the encoder to usepublic EncodedWriter(java.io.Writer out,
java.lang.String contextName)
throws UnsupportedContextException
new EncodedWriter(out, Encoders.forName(contextName));
out - the target for all writescontextName - the encoding context name.UnsupportedContextException - if the contextName is unrecognized or not supported.public void write(char[] cbuf,
int off,
int len)
throws java.io.IOException
write in class java.io.Writerjava.io.IOExceptionprivate void flushBufferToWriter()
throws java.io.IOException
java.io.IOException - thrown by the wrapped output.private void flushLeftOver(java.nio.CharBuffer input)
throws java.io.IOException
input - the next input to encode, or null if at end of file.java.io.IOException - from the underlying writer.public void flush()
throws java.io.IOException
flush in interface java.io.Flushableflush in class java.io.Writerjava.io.IOExceptionpublic void close()
throws java.io.IOException
close in interface java.io.Closeableclose in interface java.lang.AutoCloseableclose in class java.io.Writerjava.io.IOException