C2BConverterpublic final class C2BConverter extends Object 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 ) |
Fields Summary |
---|
private static org.apache.juli.logging.Log | log | private IntermediateOutputStream | ios | private WriteConvertor | conv | private ByteChunk | bb | private String | enc |
Constructors Summary |
---|
public C2BConverter(ByteChunk output, String encoding)Create a converter, with bytes going to a byte buffer
this.bb=output;
ios=new IntermediateOutputStream( output );
conv=new WriteConvertor( ios, encoding );
this.enc=encoding;
| public C2BConverter(String encoding)Create a converter
this( new ByteChunk(1024), encoding );
|
Methods Summary |
---|
public final void | convert(char c)Generate the bytes using the specified encoding
conv.write( c );
| public final void | convert(MessageBytes mb)Convert a message bytes chars to bytes
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);
| public final void | convert(char[] c, int off, int len)Generate the bytes using the specified encoding
conv.write( c, off, len );
| public final void | convert(java.lang.String s, int off, int len)Generate the bytes using the specified encoding
conv.write( s, off, len );
| public final void | convert(java.lang.String s)Generate the bytes using the specified encoding
conv.write( s );
| public final void | flushBuffer()Flush any internal buffers into the ByteOutput or the internal
byte[]
conv.flush();
| public ByteChunk | getByteChunk()
return bb;
| public java.lang.String | getEncoding()
return enc;
| public final void | recycle()Reset the internal state, empty the buffers.
The encoding remain in effect, the internal buffers remain allocated.
conv.recycle();
bb.recycle();
| public void | setByteChunk(ByteChunk bb)
this.bb=bb;
ios.setByteChunk( bb );
|
|