FileDocCategorySizeDatePackage
Packet.javaAPI DocphoneME MR2 API (J2ME)13730Wed May 02 17:59:48 BST 2007com.sun.cldchi.tools.memoryprofiler.jdwp

Packet

public class Packet extends ByteBuffer
This class encapsulates JDWP packet. It based on ByteBuffer but adds methods for working with data specific for JDWP packet. This class is not used directly, its subclasses Command and Reply are used instead. For information about JDWP packet see JDWP specification.
see
jdwp.ByteBuffer
see
jdwp.Command
see
jdwp.Reply

Fields Summary
public static final int
flNoFlags
JDWP packet flag "no flags". Indicates that the packet is a command.
public static final int
flReply
JDWP packet flag Reply. Indicates that the packet is a reply.
public static final int
LengthOffset
Offset of the "packet length" field in the JDWP packet.
public static final int
IdOffset
Offset of the "packet ID" field in the JDWP packet.
public static final int
FlagsOffset
Offset of the "flags" field in the JDWP packet.
public static final int
CommandOffset
Offset of the "command number" field in the JDWP packet.
public static final int
ErrorCodeOffset
Offset of the "error code" field in the JDWP packet.
public static final int
PacketHeaderSize
Size of JDWP packet's header.
Constructors Summary
public Packet()
Create a new JDWP packet fills its header by zeros.


                   
      
	super();
	while (length() < PacketHeaderSize){
            addByte(0);
        }
    
Methods Summary
public voidaddFieldID(long b)
Adds a field ID to the end of JDWP packet.

param
b ID to be added

	addID(b, jdwp.fieldIDSize);
    
public voidaddFrameID(long b)
Adds a frame ID to the end of JDWP packet.

param
b ID to be added

	addID(b, jdwp.frameIDSize);
    
public voidaddMethodID(long b)
Adds a method ID to the end of JDWP packet.

param
b ID to be added

	addID(b, jdwp.methodIDSize);
    
public voidaddObjectID(long b)
Adds an object ID to the end of JDWP packet.

param
b ID to be added

	addID(b, jdwp.objectIDSize);
    
public voidaddReferenceTypeID(long b)
Adds a reference type ID to the end of JDWP packet.

param
b ID to be added

	addID(b, jdwp.referenceTypeIDSize);
    
private voiddoParse(java.lang.String how, java.util.Vector v)
Performs the parsing of the JDWP oacket in fact. The all the parsing rules that described in the description of parse method are the same besides of absence of '.' symbol in the mask.

param
how a mask that describes types of elements
param
v a vector for keeping results
see
#parse(java.lang.String)


	int index = 0;
	char[] h = how.toCharArray();

	while (index < h.length) {
            switch (h[index]) {
                case 'b":
                    v.add(new Integer(getByte()));
                    break;
		case 'i":
                    v.add(new Integer(getInt()));
                    break;
		case 'S":
                    v.add(new Integer(getShort()));
                    break;
		case 'l":
                    v.add(new Long(getLong()));
                    break;
		case 's":
                    v.add(getString());
                    break;
		case 'f":
                    v.add(new Long(getFieldID()));
                    break;
		case 'm":
                    v.add(new Long(getMethodID()));
                    break;
                case 'o":
                    v.add(new Long(getObjectID()));
                    break;
		case 'r":
                    v.add(new Long(getReferenceTypeID()));
                    break;
		case 'F":
                    v.add(new Long(getFrameID()));
                    break;
                case 'v":
                    int vtype = getByte();
                    v.add(new Integer(vtype));
                    switch (vtype) {
			case jdwp.tagARRAY:
			case jdwp.tagOBJECT:
                            v.add(new Long(getObjectID()));
                            break;
			case jdwp.tagBYTE:
                            v.add(new Integer(getByte()));
                            break;
			case jdwp.tagINT:
                            v.add(new Integer(getInt()));
                            break;
			case jdwp.tagSHORT:
                            v.add(new Integer(getShort()));
                            break;
			case jdwp.tagVOID:
                            v.add("void value");
                            break;
			case jdwp.tagBOOLEAN:
                            v.add(new Integer(getByte()));
                            break;
			case jdwp.tagLONG:
                            v.add(new Long(getLong()));
                            break;
			default:
                            throw new BoundException();
                    }
                    break;

                case '(":
                    if (index == 0)
                        throw new BoundException();
                    
                    if (h[index - 1] != 'i")
                        throw new BoundException();

                    int n = ((Integer) v.elementAt(v.size() - 1)).intValue();

                    if (n < 0)
			throw new BoundException();
                    int pos = index + 1;
                    int cnt = 1;
                    int last = -1;                 
                    while (pos < h.length) {
			if (h[pos] == '(")
                            cnt++;

			if (h[pos] == ')") {
                            cnt--;
                            if (cnt == 0) {
				last = pos;
				break;
                            }
			}
			pos++;
                    }

                    if (last == -1)
			throw new BoundException();

                    String s = new String(h, index + 1, last - index - 1);
                    for (int i = 0; i < n; i++)
			doParse(s, v);
                    index = last;
                    break;

		default:
                    throw new BoundException();
            }
            index++;
	}
    
public intgetDataSize()
Returns size of packet's data (i.e., size of the packet excluding header).

return
size of packet's data

	return length() - PacketHeaderSize;
    
public longgetFieldID()
Tries to read next field ID from the buffer. Value is read is one that is pointed by reading marker. After completing the operation the reading marker is incremented.

return
current field ID from the buffer
throws
BoundException if value to be read is outside the filled area

	return getID(jdwp.fieldIDSize);
    
public intgetFlags()
Returns flags of the JDWP packet.

return
flags of the JDWP packet.

        return bytes[FlagsOffset] & 0xff;
    
public longgetFrameID()
Tries to read next frame ID from the buffer. Value is read is one that is pointed by reading marker. After completing the operation the reading marker is incremented.

return
current frame ID from the buffer
throws
BoundException if value to be read is outside the filled area

	return getID(jdwp.frameIDSize);
    
public intgetID()
Returns ID of the JDWP packet.

return
ID of the JDWP packet

        int id = 0;

        try {
            id = getInt(IdOffset);
        }
        catch (BoundException e) {};
		return id;
    
public longgetMethodID()
Tries to read next method ID from the buffer. Value is read is one that is pointed by reading marker. After completing the operation the reading marker is incremented.

return
current method ID from the buffer
throws
BoundException if value to be read is outside the filled area

	return getID(jdwp.methodIDSize);
    
public longgetObjectID()
Tries to read next object ID from the buffer. Value is read is one that is pointed by reading marker. After completing the operation the reading marker is incremented.

return
current object ID from the buffer
throws
BoundException if value to be read is outside the filled area

	return getID(jdwp.objectIDSize);
    
public longgetReferenceTypeID()
Tries to read next reference type ID from the buffer. Value is read is one that is pointed by reading marker. After completing the operation the reading marker is incremented.

return
current reference type ID from the buffer
throws
BoundException if value to be read is outside the filled area

	return getID(jdwp.referenceTypeIDSize);
    
public java.util.Vectorparse(java.lang.String how)
Parses the JDWP packet according to the specified mask. The mask specifies what elements are contained in JDWP packet's data. The rules are as follows:
  • b - a byte value
  • i - an int value
  • S - a short value
  • l - a long value
  • s - a string value
  • f - a field ID
  • m - a method ID
  • o - an object ID
  • r - a reference type ID
  • F - a frame ID
  • v - a value. The first byte indicates type tag of the variable, the second is a variable's value.
  • . - a set of data in the end of packet that should not be parsed.
  • i(<submask>) - the first integer indicates how many times submask is appeared in the packet.
For example, the mask li(rm) means that the first element of packet's data is a long value, then an int value that indicates how many times the pair "reference type ID - method ID" is appeared later.

param
how a mask that indicates how to parse a packet.
return
a vector of parsed elements of the packet's data. The classes that represent different types of elements are written below:
  • b - java.lang.Integer
  • i - java.lang.Integer
  • S - java.lang.Integer
  • l - java.lang.Long
  • s - java.lang.String
  • f - java.lang.Long
  • m - java.lang.Long
  • o - java.lang.Long
  • r - java.lang.Long
  • F - java.lang.Long
  • v - The tag of the value is represented by java.lang.Integer. The value itself is represented according to this table


        boolean check;
	check = (how.indexOf('.") == -1);

        if (! check) {
		if (how.indexOf('.") != how.length() - 1)
                   	throw new BoundException();
		how = Tools.Left(how, how.length() - 1);
        }

	Vector v = new Vector();
	resetDataParser();
        doParse(how, v);

        if (check && (! isParsed()))
        	throw new BoundException();
		return v;
    
public voidresetDataParser()
Moves the reading marker to the beginning of packet data (after the header). To learn about reading marker see ByteBuffer.

see
jdwp.ByteBuffer

	resetParser(PacketHeaderSize);
    
public voidsetFlags(int Flags)
Sets flags of the JDWP packet.

param
Flags flags to be set

	bytes[FlagsOffset] = (byte) (Flags & 0xFF);
    
public voidsetID(int Id)
Sets ID of the JDWP packet.

param
Id ID of the JDWP packet

        try {
            putInt(IdOffset, Id);
        }
        catch (BoundException e) {};
    
public voidsetLength()
Sets "packet length" field of the JDWP packet

        try {
            putInt(LengthOffset, length());
        }
        catch (BoundException e) {};