Skip to content
Snippets Groups Projects
Commit ba07cb2e authored by Brutzman, Don's avatar Brutzman, Don
Browse files

espdu.marshal(dataOutputStream) works, copy by byteBuffer still failing

parent 8f93b538
No related branches found
No related tags found
No related merge requests found
......@@ -44,6 +44,9 @@ import edu.nps.moves.dis7.pdus.EulerAngles;
import edu.nps.moves.dis7.pdus.Pdu;
import edu.nps.moves.dis7.pdus.Vector3Double;
import edu.nps.moves.dis7.utilities.PduFactory;
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
......@@ -80,7 +83,9 @@ public class PduTrack
private String x3dOrientationInterpolatorDEF = new String();
private boolean addLineBreaksWithinKeyValues = false;
PduFactory pduFactory = new PduFactory();
protected PduFactory pduFactory = new PduFactory();
protected ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
protected DataOutputStream dataOutputStream = new DataOutputStream(byteArrayOutputStream);
private String TRACE_PREFIX = "[" + (PduTrack.class.getSimpleName()) + "] ";
/**
......@@ -807,6 +812,24 @@ public class PduTrack
return this;
}
/** Flush all buffers to reduce console scrambling while threaded
*/
protected void flushBuffers()
{
try
{
dataOutputStream.flush();
byteArrayOutputStream.flush();
byteArrayOutputStream.reset();
System.err.flush();
System.out.flush();
}
catch (IOException ioe)
{
System.out.println(TRACE_PREFIX + "flushBuffers() IOException: " + ioe.getMessage());
}
}
/** Self test to check basic operation, invoked by main()
*/
public void selfTest()
......@@ -849,34 +872,53 @@ public class PduTrack
System.out.println("=================================");
System.out.println("PduTrack pduList marshalling checks");
System.out.println();
System.out.println("= = = = = = = = = = = = = = = = =");
try
{
// int BYTE_BUFFER_SIZE = 400; // TODO what is expected max buffer size?
for (int i = 0; i < TOTAL_PDUS; i++)
{
// EntityStatePdu espdu = new EntityStatePdu();
// EntityStatePdu espdu = pduFactory.makeEntityStatePdu(); // TODO check Pdu.Type
Pdu pdu = pduTrack.getPduList().get(i);
if (!(pdu instanceof EntityStatePdu))
continue;
continue; // skip remainder of this loop
EntityStatePdu espdu = (EntityStatePdu) pdu;
byte[] byteArray = espdu.marshal();
System.out.println("espdu from pduTrack pduList");
reportPdu(espdu);
System.out.println("espdu.marshal(): " + bytesToHex(byteArray));
System.err.flush(); System.out.flush();
byte[] byteArray = espdu.marshal();
System.out.println("espdu.marshal() byteArray: " + bytesToHex(byteArray));
flushBuffers();
ByteBuffer byteBuffer = ByteBuffer.allocate(byteArray.length);
espdu.marshal(byteBuffer);
reportPdu(espdu);
System.out.println("espdu.marshal(byteBuffer): " + bytesToHex(byteBuffer.array()));
System.err.flush(); System.out.flush();
flushBuffers();
espdu.marshal(dataOutputStream);
byte[] byteArrayDOS = byteArrayOutputStream.toByteArray();
System.out.println("espdu.marshal(dataOutputStream): " + bytesToHex(byteArrayDOS));
flushBuffers();
System.out.println(); // - - - - - - - - - - - - - - - - -
System.out.println("espdu.copyByteBuffer()");
reportPdu(espdu.copyByteBuffer());
byte[] byteArrayCopy = espdu.copyByteBuffer().marshal();
System.out.println("espdu.copyByteBuffer().marshal() byteArray: " + bytesToHex(byteArrayCopy));
flushBuffers();
ByteBuffer byteBufferCopy = ByteBuffer.allocate(byteArray.length); // TODO is there a better way to reset?
espdu.copyByteBuffer().marshal(byteBufferCopy);
System.out.println("espdu.copyByteBuffer().marshal(byteBufferCopy): " + bytesToHex(byteBufferCopy.array()));
flushBuffers();
espdu.copyByteBuffer().marshal(dataOutputStream);
byte[] byteArrayDosCopy = byteArrayOutputStream.toByteArray();
System.out.println("espdu.copyByteBuffer().marshal(dataOutputStream): " + bytesToHex(byteArrayDosCopy));
flushBuffers();
System.out.println();
// TODO implement, report espdu.copyDataOutputStream());
byteBuffer = ByteBuffer.allocate(byteArray.length); // TODO is there a better way to reset?
espdu.copy().marshal(byteBuffer);
reportPdu(espdu.copy());
System.out.println("espdu.copy().marshal(byteBuffer):" + bytesToHex(byteBuffer.array()));
System.err.flush(); System.out.flush();
System.out.println("= = = = = = = = = = = = = = = = =");
}
}
......
This diff is collapsed.
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