import java.net.*;
/**
 * This takes the packets from the outside world and transforms them into
 * UDPMessages according to our protocol. This is where the InvalidPacket
 * exception will be used.
 */
public class UDPMessage
{
	private ID id1;
	private ID id2;
	private TimeToLive timeToLive;
	private byte[] message;

	public UDPMessage(ID id1, ID id2, TimeToLive timeToLive, String message)
	{
		this(id1, id2, timeToLive, message.getBytes());
	}//UDPMessage

	public UDPMessage(ID id1, ID id2, TimeToLive timeToLive, byte[] message)
	{
		this.id1 = id1;
		this.id2 = id2;
		this.timeToLive = timeToLive;
		this.message = message;
	}//UDPMessage

	public UDPMessage(DatagramPacket datagramPacket)
	{
		byte[]		data;
		int			messageLength;
		ID 			id1;
		ID			id2;
		TimeToLive	timeToLive;
		byte[]		message;
		byte[]		ttl;
		int			count;

		data = datagramPacket.getData();
		ttl = new byte[TimeToLive.getLengthInBytes()];

		count = 0;
		if(data.length>0 && data.length<512)
		{
			id1 = new ID(datagramPacket, 0);
			id2 = new ID(datagramPacket, ID.getLengthInBytes());
			for(int i= id1.getLengthInBytes()*2; i<((id1.getLengthInBytes()*2)+ttl.length); i++)
			{
				ttl[count] = data[i];
				count = count+1;
			}
			timeToLive = new TimeToLive(ttl);
			messageLength = datagramPacket.getLength()-id1.getLengthInBytes()*2 + ttl.length;
			message = new byte[messageLength];
			System.arraycopy(data, id1.getLengthInBytes()*2 + ttl.length, message, 0, messageLength);
		}
		else
		{
			throw new InvalidPacketFormatException(datagramPacket, "Error: Data is the wrong size");
		}
	}//UDPMessage

	public DatagramPacket getDatagramPacket()
	{
		return getDatagramPacket(this.message);
	}//getDatagramPacket

	public DatagramPacket getDatagramPacket(String payload)
	{
		return getDatagramPacket(payload.getBytes());
	}//getDatagramPacket

	public DatagramPacket getDatagramPacket(byte[] payload)
	{
		ID			id1;
		ID 			id2;
		String 		myData;
		TimeToLive	ttl;
		int			size;
		byte[]		buffer;

		id1 = ID.idFactory();
		id2 = ID.idFactory();
		ttl = new TimeToLive(75);
		myData = "Hi";

		size = (ID.getLengthInBytes() *2) + timeToLive.getLengthInBytes() + myData.getBytes().length;
		buffer = new byte[size];

		System.arraycopy(id1.getBytes(), 0, buffer, 0, ID.getLengthInBytes());
		System.arraycopy(id2.getBytes(), 0, buffer, 0, ID.getLengthInBytes());
		System.arraycopy(ttl.getBytes(), 0, buffer, ID.getLengthInBytes()*2, TimeToLive.getLengthInBytes());
		System.arraycopy(myData.getBytes(), 0, buffer, ID.getLengthInBytes()*2 + TimeToLive.getLengthInBytes(), myData.getBytes().length);
		System.arraycopy(payload, 0, buffer, ID.getLengthInBytes()*2 + TimeToLive.getLengthInBytes(), myData.getBytes().length + myData.getBytes().length);

		return new DatagramPacket(buffer, size);

	}//getDatagramPacket

	public ID getID1()
	{
		return this.id1;
	}//ID1

	public ID getID2()
	{
		return this.id2;
	}//ID2

	public TimeToLive getTimeToLive()
	{
		return this.timeToLive;
	}//getTimeToLive

	public byte[] getMessage()
	{
		return this.message;
	}//getMessage

	public static int getMaximumPacketSizeInBytes()
	{
		return 512-(ID.getLengthInBytes()*2)-TimeToLive.getLengthInBytes();
	}//getMaximumPacketSizeInBytes

	public static int getMinimumPacketSizeInBytes()
	{
		return (ID.getLengthInBytes()*2)-TimeToLive.getLengthInBytes();
	}//getMinimumPacketSizeInByte

}//class

@@ -1924,27 +1924,8 @@
 d2;%0A
-%09%09String %09%09myData;%0A
 %09%09Ti
@@ -2050,25 +2050,8 @@
 75);
-%0A%09%09myData = %22Hi%22;
 %0A%0A%09%09
@@ -2118,33 +2118,23 @@
 tes() + 
-myData.getBytes()
+payload
 .length;
@@ -2430,33 +2430,23 @@
 raycopy(
-myData.getBytes()
+payload
 , 0, buf
@@ -2507,33 +2507,23 @@
 ytes(), 
-myData.getBytes()
+payload
 .length)
@@ -2624,52 +2624,32 @@
 (), 
-myData.getBytes().length + myData.getBytes()
+payload.length + payload
 .len

Update UDPMessage.java