Skip to content
Snippets Groups Projects
Commit 1b330074 authored by J. M. Bailey's avatar J. M. Bailey
Browse files

Add raw listener api

parent e31d4845
No related branches found
No related tags found
No related merge requests found
...@@ -19,6 +19,9 @@ import static edu.nps.moves.dis7.util.playerrecorder.Recorder.*; ...@@ -19,6 +19,9 @@ import static edu.nps.moves.dis7.util.playerrecorder.Recorder.*;
public class Player public class Player
{ {
public interface RawListener {
void receiveBytes(byte[] ba);
}
private Path disLogDirectory; private Path disLogDirectory;
private String ip; private String ip;
private int port; private int port;
...@@ -44,7 +47,17 @@ public class Player ...@@ -44,7 +47,17 @@ public class Player
private BufferedReader brdr; private BufferedReader brdr;
private Long startNanoTime = null; private Long startNanoTime = null;
private boolean paused = false; private boolean paused = false;
private boolean netSend = true;
private RawListener rawListener = null;
public void sendToNet(boolean tf)
{
netSend = tf;
}
public void addRawListener(RawListener lis)
{
rawListener = lis;
}
@SuppressWarnings("StatementWithEmptyBody") @SuppressWarnings("StatementWithEmptyBody")
public void begin() public void begin()
{ {
...@@ -63,7 +76,8 @@ public class Player ...@@ -63,7 +76,8 @@ public class Player
}); });
//Arrays.sort(fs, Comparator.comparing(File::getName)); //Arrays.sort(fs, Comparator.comparing(File::getName));
dsock = new DatagramSocket(); if(netSend)
dsock = new DatagramSocket();
Base64.Decoder decdr = Base64.getDecoder(); Base64.Decoder decdr = Base64.getDecoder();
for (File f : fs) { for (File f : fs) {
...@@ -110,9 +124,13 @@ public class Player ...@@ -110,9 +124,13 @@ public class Player
byte[] buffer = decdr.decode(sa[1]); byte[] buffer = decdr.decode(sa[1]);
DatagramPacket packet = new DatagramPacket(buffer, buffer.length, addr, port); if(netSend) {
dsock.send(packet); DatagramPacket packet = new DatagramPacket(buffer, buffer.length, addr, port);
dsock.send(packet);
}
if(rawListener != null) {
rawListener.receiveBytes(buffer);
}
pduCount++; pduCount++;
if (scenarioPduCount != null) if (scenarioPduCount != null)
scenarioPduCount++; scenarioPduCount++;
...@@ -125,6 +143,8 @@ public class Player ...@@ -125,6 +143,8 @@ public class Player
} }
brdr.close(); brdr.close();
} }
if(rawListener != null)
rawListener.receiveBytes(null); // indicate the end
} }
catch (Exception ex) { catch (Exception ex) {
System.err.println("Exception reading/writing pdus: "+ex.getClass().getSimpleName()+": "+ex.getLocalizedMessage()); System.err.println("Exception reading/writing pdus: "+ex.getClass().getSimpleName()+": "+ex.getLocalizedMessage());
......
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