Methods Summary |
---|
public void | appendByte(int val)
buf[pos++] = (byte)val;
|
public void | appendByteChunk(org.apache.tomcat.util.buf.ByteChunk bc)
if(bc==null) {
log.error("appendByteChunk() null");
appendInt( 0);
appendByte(0);
return;
}
byte[] bytes = bc.getBytes();
int start=bc.getStart();
int length = bc.getLength();
appendInt( length );
cpBytes(bytes, start, length);
appendByte(0);
|
public void | appendBytes(org.apache.tomcat.util.buf.MessageBytes mb)Write a String out at the current write position. Strings are
encoded with the length in two bytes first, then the string, and
then a terminating \0 (which is not included in the
encoded length). The terminator is for the convenience of the C
code, where it saves a round of copying. A null string is
encoded as a string with length 0.
if(mb==null || mb.isNull() ) {
appendInt( 0);
appendByte(0);
return;
}
// XXX Convert !!
ByteChunk bc= mb.getByteChunk();
appendByteChunk(bc);
|
public void | appendBytes(byte[] b, int off, int numBytes)Copy a chunk of bytes into the packet, starting at the current
write position. The chunk of bytes is encoded with the length
in two bytes first, then the data itself, and finally a
terminating \0 (which is not included in the encoded
length).
appendInt( numBytes );
cpBytes( b, off, numBytes );
appendByte(0);
|
public void | appendInt(int val)Add an int.
buf[pos++] = (byte) ((val >>> 8) & 0xFF);
buf[pos++] = (byte) (val & 0xFF);
|
public void | appendLongInt(int val)
buf[pos++] = (byte) ((val >>> 24) & 0xFF);
buf[pos++] = (byte) ((val >>> 16) & 0xFF);
buf[pos++] = (byte) ((val >>> 8) & 0xFF);
buf[pos++] = (byte) (val & 0xFF);
|
private void | cpBytes(byte[] b, int off, int numBytes)
if( pos + numBytes >= buf.length ) {
log.error("Buffer overflow: buffer.len=" + buf.length + " pos=" +
pos + " data=" + numBytes );
dump("Overflow/coBytes");
log.error( "Overflow ", new Throwable());
return;
}
System.arraycopy( b, off, buf, pos, numBytes);
pos += numBytes;
// buf[pos + numBytes] = 0; // Terminating \0
|
public void | dump(java.lang.String msg)
if( log.isDebugEnabled() )
log.debug( msg + ": " + buf + " " + pos +"/" + (len + 4));
int max=pos;
if( len + 4 > pos )
max=len+4;
if( max >1000 ) max=1000;
if( log.isDebugEnabled() )
for( int j=0; j < max; j+=16 )
log.debug( hexLine( buf, j, len ));
|
public void | end()For a packet to be sent to the web server, finish the process of
accumulating data and write the length of the data payload into
the header.
len=pos;
int dLen=len-4;
buf[0] = (byte)0x41;
buf[1] = (byte)0x42;
buf[2]= (byte)((dLen>>>8 ) & 0xFF );
buf[3] = (byte)(dLen & 0xFF);
|
public byte[] | getBuffer()
return buf;
|
public byte | getByte()
byte res = buf[pos++];
return res;
|
public void | getBytes(org.apache.tomcat.util.buf.MessageBytes mb)
int length = getInt();
if( (length == 0xFFFF) || (length == -1) ) {
mb.recycle();
return;
}
mb.setBytes( buf, pos, length );
mb.getCharChunk().recycle();
pos += length;
pos++; // Skip the terminating \0
|
public int | getBytes(byte[] dest)Copy a chunk of bytes from the packet into an array and advance
the read position past the chunk. See appendBytes() for details
on the encoding.
int length = getInt();
if( length > buf.length ) {
// XXX Should be if(pos + length > buff.legth)?
log.error("getBytes() buffer overflow " + length + " " + buf.length );
}
if( (length == 0xFFFF) || (length == -1) ) {
log.info("Null string " + length);
return 0;
}
System.arraycopy( buf, pos, dest, 0, length );
pos += length;
pos++; // Skip terminating \0 XXX I believe this is wrong but harmless
return length;
|
public int | getHeaderLength()
return 4;
|
public int | getInt()Read an integer from packet, and advance the read position past
it. Integers are encoded as two unsigned bytes with the
high-order byte first, and, as far as I can tell, in
little-endian order within each byte.
int b1 = buf[pos++] & 0xFF; // No swap, Java order
int b2 = buf[pos++] & 0xFF;
return (b1<<8) + b2;
|
public int | getLen()
return len;
|
public int | getLongInt()Read a 32 bits integer from packet, and advance the read position past
it. Integers are encoded as four unsigned bytes with the
high-order byte first, and, as far as I can tell, in
little-endian order within each byte.
int b1 = buf[pos++] & 0xFF; // No swap, Java order
b1 <<= 8;
b1 |= (buf[pos++] & 0xFF);
b1 <<= 8;
b1 |= (buf[pos++] & 0xFF);
b1 <<=8;
b1 |= (buf[pos++] & 0xFF);
return b1;
|
private static java.lang.String | hex(int x)
// if( x < 0) x=256 + x;
String h=Integer.toHexString( x );
if( h.length() == 1 ) h = "0" + h;
return h.substring( h.length() - 2 );
|
public static java.lang.String | hexLine(byte[] buf, int start, int len)
StringBuffer sb=new StringBuffer();
for( int i=start; i< start+16 ; i++ ) {
if( i < len + 4)
sb.append( hex( buf[i] ) + " ");
else
sb.append( " " );
}
sb.append(" | ");
for( int i=start; i < start+16 && i < len + 4; i++ ) {
if( ! Character.isISOControl( (char)buf[i] ))
sb.append( new Character((char)buf[i]) );
else
sb.append( "." );
}
return sb.toString();
|
public byte | peekByte()
byte res = buf[pos];
return res;
|
public int | peekInt()
int b1 = buf[pos] & 0xFF; // No swap, Java order
int b2 = buf[pos+1] & 0xFF;
return (b1<<8) + b2;
|
public int | processHeader()
pos = 0;
int mark = getInt();
len = getInt();
if( mark != 0x1234 && mark != 0x4142 ) {
// XXX Logging
log.error("BAD packet signature " + mark);
dump( "In: " );
return -1;
}
if( log.isDebugEnabled() )
log.debug( "Received " + len + " " + buf[0] );
return len;
|
public void | reset()Prepare this packet for accumulating a message from the container to
the web server. Set the write position to just after the header
(but leave the length unwritten, because it is as yet unknown).
len = 4;
pos = 4;
|