Commit afe8d701 by Keith Seitz Committed by Keith Seitz

JdwpPacket.java (write): New method.

        * gnu/classpath/jdwp/transport/JdwpPacket.java (write): New method.
        (myWrite): New abstract method.
        (toBytes): Remove.
        (myToBytes): Remove.
        * gnu/classpath/jdwp/transport/JdwpReplyPacket.java (myWrite): New
        method.
        * gnu/classpath/jdwp/transport/JdwpCommandPacket.java (myWrite): New
        method.
        * gnu/classpath/jdwp/transport/JdwpConnection.java (sendPacket): Use
        JdwpPacket.write instead of JdwpPacket.toBytes.

From-SVN: r101472
parent 1b0618bf
2005-06-30 Keith Seitz <keiths@redhat.com> 2005-06-30 Keith Seitz <keiths@redhat.com>
* gnu/classpath/jdwp/transport/JdwpPacket.java (write): New method.
(myWrite): New abstract method.
(toBytes): Remove.
(myToBytes): Remove.
* gnu/classpath/jdwp/transport/JdwpReplyPacket.java (myWrite): New
method.
* gnu/classpath/jdwp/transport/JdwpCommandPacket.java (myWrite): New
method.
* gnu/classpath/jdwp/transport/JdwpConnection.java (sendPacket): Use
JdwpPacket.write instead of JdwpPacket.toBytes.
2005-06-30 Keith Seitz <keiths@redhat.com>
* gnu/classpath/jdwp/transport/JdwpConnection.java (sendEvent): New * gnu/classpath/jdwp/transport/JdwpConnection.java (sendEvent): New
method. method.
(_bytes): New member. (_bytes): New member.
......
...@@ -39,6 +39,9 @@ exception statement from your version. */ ...@@ -39,6 +39,9 @@ exception statement from your version. */
package gnu.classpath.jdwp.transport; package gnu.classpath.jdwp.transport;
import java.io.DataOutputStream;
import java.io.IOException;
/** /**
* A class representing a JDWP command packet. * A class representing a JDWP command packet.
* This class adds command set and command to the packet header * This class adds command set and command to the packet header
...@@ -137,13 +140,10 @@ public class JdwpCommandPacket extends JdwpPacket ...@@ -137,13 +140,10 @@ public class JdwpCommandPacket extends JdwpPacket
} }
// Writes the command packet data into the given buffer // Writes the command packet data into the given buffer
protected int myToBytes (byte[] bytes, int index) protected void myWrite (DataOutputStream dos)
throws IOException
{ {
// Need to add command set & command dos.writeByte (getCommandSet ());
int i = 0; dos.writeByte (getCommand ());
bytes[index + i++] = getCommandSet ();
bytes[index + i++] = getCommand ();
return i;
} }
} }
...@@ -258,8 +258,7 @@ public class JdwpConnection ...@@ -258,8 +258,7 @@ public class JdwpConnection
public void sendPacket (JdwpPacket pkt) public void sendPacket (JdwpPacket pkt)
throws IOException throws IOException
{ {
byte[] data = pkt.toBytes (); pkt.write (_outStream);
_outStream.write (data, 0, data.length);
} }
/** /**
......
...@@ -39,6 +39,9 @@ exception statement from your version. */ ...@@ -39,6 +39,9 @@ exception statement from your version. */
package gnu.classpath.jdwp.transport; package gnu.classpath.jdwp.transport;
import java.io.DataOutputStream;
import java.io.IOException;
/** /**
* All command and reply packets in JDWP share * All command and reply packets in JDWP share
* common header type information: * common header type information:
...@@ -238,49 +241,38 @@ public abstract class JdwpPacket ...@@ -238,49 +241,38 @@ public abstract class JdwpPacket
return null; return null;
} }
// Put subclass information into bytes /**
protected abstract int myToBytes (byte[] bytes, int index); * Put subclass information onto the stream
*
* @param dos the output stream to which to write
*/
protected abstract void myWrite (DataOutputStream dos)
throws IOException;
// Convert this packet to it byte representation (ready to send on the wire) /**
// NOTE: All integers should be big-endian. * Writes the packet to the output stream
public byte[] toBytes () *
* @param dos the output stream to which to write the packet
*/
public void write (DataOutputStream dos)
throws IOException
{ {
// Allocate a new array to hold contents of packet
int length = getLength ();
byte[] bytes = new byte[length];
int i = 0;
//
// Packet layout: length, id, flags, packet-specific, data (optional)
//
// length // length
bytes[i++] = (byte) (length >>> 24); int length = getLength ();
bytes[i++] = (byte) (length >>> 16); dos.writeInt (length);
bytes[i++] = (byte) (length >>> 8);
bytes[i++] = (byte) length;
// id // ID
bytes[i++] = (byte) (getId () >>> 24); dos.writeInt (getId ());
bytes[i++] = (byte) (getId () >>> 16);
bytes[i++] = (byte) (getId () >>> 8);
bytes[i++] = (byte) getId ();
// flag // flag
bytes[i++] = getFlags (); dos.writeByte (getFlags ());
// packet-specific stuff // packet-specific stuff
i += myToBytes (bytes, i); myWrite (dos);
// data (if any) // data (if any)
byte[] data = getData (); byte[] data = getData ();
if (data.length > 0 && i < length) if (data != null && data.length > 0)
{ dos.write (data, 0, data.length);
// Would it pay to be over cautious?
System.arraycopy (data, 0, bytes, i, data.length);
}
return bytes;
} }
} }
...@@ -39,6 +39,9 @@ exception statement from your version. */ ...@@ -39,6 +39,9 @@ exception statement from your version. */
package gnu.classpath.jdwp.transport; package gnu.classpath.jdwp.transport;
import java.io.DataOutputStream;
import java.io.IOException;
/** /**
* A class represents a JDWP reply packet. * A class represents a JDWP reply packet.
* This class adds an error code to the packet header information * This class adds an error code to the packet header information
...@@ -115,13 +118,9 @@ public class JdwpReplyPacket extends JdwpPacket ...@@ -115,13 +118,9 @@ public class JdwpReplyPacket extends JdwpPacket
} }
// Writes the command packet data into the given buffer // Writes the command packet data into the given buffer
protected int myToBytes (byte[] bytes, int index) protected void myWrite (DataOutputStream dos)
throws IOException
{ {
// Need to add error code dos.writeShort (getErrorCode ());
int i = 0;
bytes[index + i++] = (byte) (getErrorCode () >>> 8);
bytes[index + i++] = (byte) getErrorCode ();
return i;
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment