Skip to content
Snippets Groups Projects
Commit 7833d696 authored by garrettloeffelman's avatar garrettloeffelman
Browse files

LoeffelmanSeverson Final Project with documentation

parent 2ed037e7
No related branches found
No related tags found
No related merge requests found
......@@ -5,6 +5,7 @@
*/
package MV3500Cohort2018JulySeptember.FinalProject.LoeffelmanSeverson;
import edu.nps.moves.dis.CommentPdu;
import edu.nps.moves.dis.EntityID;
import edu.nps.moves.dis.EntityStatePdu;
......@@ -59,6 +60,7 @@ public class LoeffelmanSeversonDISImageReceiver {
while (true) // Loop infinitely, receiving datagrams
{
//buffer needs to be resized to be able to accept image sizes
byte buffer[] = new byte[100000]; // typical MTU size
packet = new DatagramPacket(buffer, buffer.length); // reset
......@@ -72,7 +74,11 @@ public class LoeffelmanSeversonDISImageReceiver {
String pduTypeName = pdu.getClass().getName();
short protocolFamily = pdu.getProtocolFamily(); // TODO get string enumeration
//If we receive a comment PDU, we are going to look for a picture specifically
if(pdu.getPduTypeEnum() == PduType.COMMENT){
//Set up data structures, get the list of variableDatums, and
//get the first and only VariableDatum, and the arrayList
//of OneByteChunks from the variableDatum
CommentPdu cPdu = (CommentPdu)pdu;
ArrayList<VariableDatum> payload = (ArrayList)cPdu.getVariableDatums();
VariableDatum payloadWrapper = payload.get(0);
......@@ -80,13 +86,19 @@ public class LoeffelmanSeversonDISImageReceiver {
byte[] imageByte = new byte[100000];
//Loop through the arrayList of OneByteChunks and
//populate the byte array representation of the image
for(int i = 0; i < oBC.size(); i++){
imageByte[i] = oBC.get(i).getOtherParameters()[0];
}
//Convert that byte array into an input stream and into
//an image using a buffered image reader.
ByteArrayInputStream bais = new ByteArrayInputStream(imageByte);
BufferedImage bimage = ImageIO.read(bais);
image = bimage;
//Display the image using java swing utilities
JFrame frame = new JFrame();
frame.setSize(300, 300);
JLabel label = new JLabel(new ImageIcon(image));
......
......@@ -108,17 +108,24 @@ public class LoeffelmanSeversonDISImageSender {
break;
case COMMENT:
//Initialize PDU and image
aPdu = new CommentPdu();
CommentPdu cPdu = (CommentPdu)aPdu;
BufferedImage image = ImageIO.read(url1);
//Convert image to a byte array
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageIO.write(image, "png", baos);
byte[] buffer;
buffer = baos.toByteArray();
//Instaniate data structures for holding bytes
ArrayList<VariableDatum> payload = new ArrayList<VariableDatum>();
ArrayList<OneByteChunk> payloadWrapper = new ArrayList<OneByteChunk>();
VariableDatum variableDatum = new VariableDatum();
//Loop through, create OneByteChunk arrays of size 1
//and place them in ArrayList of OneByteChunks
for(int i = 0; i < buffer.length; i++){
OneByteChunk oBC = new OneByteChunk();
byte[] oneBite = new byte[1];
......@@ -127,10 +134,13 @@ public class LoeffelmanSeversonDISImageSender {
payloadWrapper.add(oBC);
}
System.out.println("Sending Picture");
//Add the arrayList of OneByteChunks to the variable datum
variableDatum.setVariableData(payloadWrapper);
//Add the variableDatum to the arraylist
payload.add(variableDatum);
//Set the variableDatum for the PDU to be sent
cPdu.setVariableDatums(payload);
break;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment