org.apache.tomcat.util.buf
final class: WriteConvertor [javadoc |
source]
java.lang.Object
java.io.Writer
java.io.OutputStreamWriter
org.apache.tomcat.util.buf.WriteConvertor
All Implemented Interfaces:
Closeable, Flushable, Appendable
Special writer class, where close() is overritten. The default implementation
would set byteOutputter to null, and the writter can't be recycled.
Note that the flush method will empty the internal buffers _and_ call
flush on the output stream - that's why we use an intermediary output stream
that overrides flush(). The idea is to have full control: flushing the
char->byte converter should be independent of flushing the OutputStream.
When a WriteConverter is created, it'll allocate one or 2 byte buffers,
with a 8k size that can't be changed ( at least in JDK1.1 -> 1.4 ). It would
also allocate a ByteOutputter or equivalent - again some internal buffers.
It is essential to keep this object around and reuse it. You can use either
pools or per thread data - but given that in most cases a converter will be
needed for every thread and most of the time only 1 ( or 2 ) encodings will
be used, it is far better to keep it per thread and eliminate the pool
overhead too.
| Methods from java.io.Writer: |
|---|
|
append, append, append, append, append, append, close, flush, write, write, write, write, write |
| Method from org.apache.tomcat.util.buf.WriteConvertor Detail: |
public final void close() throws IOException {
// NOTHING
// Calling super.close() would reset out and cb.
}
Overriden - will do nothing but reset internal state. |
public final void flush() throws IOException {
// Will flushBuffer and out()
// flushBuffer put any remaining chars in the byte[]
super.flush();
}
Flush the characters only |
public final void recycle() {
ios.disable();
try {
// System.out.println("Reseting writer");
flush();
} catch( Exception ex ) {
ex.printStackTrace();
}
ios.enable();
}
|
public final void write(char[] cbuf,
int off,
int len) throws IOException {
// will do the conversion and call write on the output stream
super.write( cbuf, off, len );
}
|