Efficient conversion of character to bytes.
This uses the standard JDK mechansim - a writer - but provides mechanisms
to recycle all the objects that are used. It is compatible with JDK1.1 and up,
( nio is better, but it's not available even in 1.2 or 1.3 )
| Method from org.apache.tomcat.util.buf.C2BConverter Detail: |
public final void convert(String s) throws IOException {
conv.write( s );
}
Generate the bytes using the specified encoding |
public final void convert(char c) throws IOException {
conv.write( c );
}
Generate the bytes using the specified encoding |
public final void convert(MessageBytes mb) throws IOException {
int type=mb.getType();
if( type==MessageBytes.T_BYTES )
return;
ByteChunk orig=bb;
setByteChunk( mb.getByteChunk());
bb.recycle();
bb.allocate( 32, -1 );
if( type==MessageBytes.T_STR ) {
convert( mb.getString() );
// System.out.println("XXX Converting " + mb.getString() );
} else if( type==MessageBytes.T_CHARS ) {
CharChunk charC=mb.getCharChunk();
convert( charC.getBuffer(),
charC.getOffset(), charC.getLength());
//System.out.println("XXX Converting " + mb.getCharChunk() );
} else {
if (log.isDebugEnabled())
log.debug("XXX unknowon type " + type );
}
flushBuffer();
//System.out.println("C2B: XXX " + bb.getBuffer() + bb.getLength());
setByteChunk(orig);
}
Convert a message bytes chars to bytes |
public final void convert(char[] c,
int off,
int len) throws IOException {
conv.write( c, off, len );
}
Generate the bytes using the specified encoding |
public final void convert(String s,
int off,
int len) throws IOException {
conv.write( s, off, len );
}
Generate the bytes using the specified encoding |
public final void flushBuffer() throws IOException {
conv.flush();
}
Flush any internal buffers into the ByteOutput or the internal
byte[] |
public ByteChunk getByteChunk() {
return bb;
}
|
public String getEncoding() {
return enc;
}
|
public final void recycle() {
conv.recycle();
bb.recycle();
}
Reset the internal state, empty the buffers.
The encoding remain in effect, the internal buffers remain allocated. |
public void setByteChunk(ByteChunk bb) {
this.bb=bb;
ios.setByteChunk( bb );
}
|