org.apache.coyote.ajp
Class AjpMessage

java.lang.Object
  extended byorg.apache.coyote.ajp.AjpMessage

public class AjpMessage
extends java.lang.Object

A single packet for communication between the web server and the container. Designed to be reused many times with no creation of garbage. Understands the format of data types for these packets. Can be used (somewhat confusingly) for both incoming and outgoing packets.

Author:
Henri Gomez, Dan Milstein, Keith Wannamaker, Kevin Seguin, Costin Manolache

Constructor Summary
AjpMessage()
           
 
Method Summary
 void appendByte(int val)
           
 void appendByteChunk(ByteChunk bc)
           
 void appendBytes(byte[] b, int off, int numBytes)
          Copy a chunk of bytes into the packet, starting at the current write position.
 void appendBytes(MessageBytes mb)
          Write a String out at the current write position.
 void appendCharChunk(CharChunk cc)
           
 void appendInt(int val)
          Add an int.
 void appendLongInt(int val)
           
 void appendString(java.lang.String str)
           
 void dump(java.lang.String msg)
           
 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.
 byte[] getBuffer()
           
 byte getByte()
           
 int getBytes(byte[] dest)
          Copy a chunk of bytes from the packet into an array and advance the read position past the chunk.
 void getBytes(MessageBytes mb)
           
 int getHeaderLength()
           
 int getInt()
          Read an integer from packet, and advance the read position past it.
 int getLen()
           
 int getLongInt()
          Read a 32 bits integer from packet, and advance the read position past it.
static java.lang.String hexLine(byte[] buf, int start, int len)
           
 byte peekByte()
           
 int peekInt()
           
 int processHeader()
           
 void reset()
          Prepare this packet for accumulating a message from the container to the web server.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AjpMessage

public AjpMessage()
Method Detail

reset

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).


end

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.


getBuffer

public byte[] getBuffer()

getLen

public int getLen()

appendInt

public void appendInt(int val)
Add an int.

Parameters:
val - The integer to write.

appendByte

public void appendByte(int val)

appendLongInt

public void appendLongInt(int val)

appendBytes

public void appendBytes(MessageBytes mb)
                 throws java.io.IOException
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.

Throws:
java.io.IOException

appendByteChunk

public void appendByteChunk(ByteChunk bc)
                     throws java.io.IOException
Throws:
java.io.IOException

appendCharChunk

public void appendCharChunk(CharChunk cc)
                     throws java.io.IOException
Throws:
java.io.IOException

appendString

public void appendString(java.lang.String str)
                  throws java.io.IOException
Throws:
java.io.IOException

appendBytes

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).

Parameters:
b - The array from which to copy bytes.
off - The offset into the array at which to start copying
numBytes - The number of bytes to copy.

getInt

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.


peekInt

public int peekInt()

getByte

public byte getByte()

peekByte

public byte peekByte()

getBytes

public void getBytes(MessageBytes mb)

getBytes

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.

Returns:
The number of bytes copied.

getLongInt

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.


getHeaderLength

public int getHeaderLength()

processHeader

public int processHeader()

dump

public void dump(java.lang.String msg)

hexLine

public static java.lang.String hexLine(byte[] buf,
                                       int start,
                                       int len)


Copyright © 2000-2005 Apache Software Foundation. All Rights Reserved.