-package com.nexuiz.demorecorder.application.democutter;\r
-import java.io.DataInputStream;\r
-import java.io.EOFException;\r
-import java.io.IOException;\r
-import java.nio.ByteBuffer;\r
-\r
-\r
-public class DemoPacket {\r
- \r
- private static final int DEMOMSG_CLIENT_TO_SERVER = 0x80000000;\r
- \r
- private DataInputStream inStream = null;\r
- private boolean isEndOfFile = false;\r
- private byte[] buffer = new byte[4]; //contains packet length\r
- private byte[] angles = new byte[12];\r
- private byte[] data;\r
- private int packetLength;\r
- private boolean isClientToServer = false;\r
- private float svcTime = -1;\r
-\r
- public DemoPacket(DataInputStream inStream) {\r
- this.inStream = inStream;\r
- \r
- try {\r
- inStream.readFully(buffer);\r
- } catch (EOFException e) {\r
- this.isEndOfFile = true;\r
- return;\r
- } catch (IOException e) {\r
- throw new DemoCutterException("Unexpected I/O Exception occurred when processing demo");\r
- }\r
- \r
- packetLength = DemoCutterUtils.convertLittleEndian(buffer);\r
- if ((packetLength & DEMOMSG_CLIENT_TO_SERVER) != 0) {\r
- packetLength = packetLength & ~DEMOMSG_CLIENT_TO_SERVER;\r
-\r
- this.isClientToServer = true;\r
- this.readAnglesAndData();\r
- return;\r
- }\r
- \r
- this.readAnglesAndData();\r
- \r
- // extract svc_time\r
- this.readSvcTime();\r
- \r
- }\r
- \r
- public boolean isEndOfFile() {\r
- return this.isEndOfFile;\r
- }\r
- \r
- public boolean isClientToServerPacket() {\r
- return this.isClientToServer;\r
- }\r
- \r
- public byte[] getOriginalLengthAsByte() {\r
- return this.buffer;\r
- }\r
- \r
- public byte[] getAngles() {\r
- return this.angles;\r
- }\r
- \r
- public byte[] getOriginalData() {\r
- return this.data;\r
- }\r
- \r
- public float getSvcTime() {\r
- return this.svcTime;\r
- }\r
- \r
- private void readAnglesAndData() {\r
- // read angles\r
- try {\r
- inStream.readFully(angles);\r
- } catch (EOFException e) {\r
- throw new DemoCutterException("Invalid Demo Packet");\r
- } catch (IOException e) {\r
- throw new DemoCutterException("Unexpected I/O Exception occurred when processing demo");\r
- }\r
-\r
- // read data\r
- data = new byte[packetLength];\r
- try {\r
- inStream.readFully(data);\r
- } catch (EOFException e) {\r
- throw new DemoCutterException("Invalid Demo Packet");\r
- } catch (IOException e) {\r
- throw new DemoCutterException("Unexpected I/O Exception occurred when processing demo");\r
- }\r
- }\r
- \r
- private void readSvcTime() {\r
- if (data[0] == 0x07) {\r
- ByteBuffer bb = ByteBuffer.allocate(4);\r
- bb.put(data, 1, 4);\r
- byte[] array = bb.array();\r
- this.svcTime = DemoCutterUtils.byteArrayToFloat(array);\r
- }\r
- }\r
-}\r
+package com.nexuiz.demorecorder.application.democutter;
+import java.io.DataInputStream;
+import java.io.EOFException;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+
+
+public class DemoPacket {
+
+ private static final int DEMOMSG_CLIENT_TO_SERVER = 0x80000000;
+
+ private DataInputStream inStream = null;
+ private boolean isEndOfFile = false;
+ private byte[] buffer = new byte[4]; //contains packet length
+ private byte[] angles = new byte[12];
+ private byte[] data;
+ private int packetLength;
+ private boolean isClientToServer = false;
+ private float svcTime = -1;
+
+ public DemoPacket(DataInputStream inStream) {
+ this.inStream = inStream;
+
+ try {
+ inStream.readFully(buffer);
+ } catch (EOFException e) {
+ this.isEndOfFile = true;
+ return;
+ } catch (IOException e) {
+ throw new DemoCutterException("Unexpected I/O Exception occurred when processing demo");
+ }
+
+ packetLength = DemoCutterUtils.convertLittleEndian(buffer);
+ if ((packetLength & DEMOMSG_CLIENT_TO_SERVER) != 0) {
+ packetLength = packetLength & ~DEMOMSG_CLIENT_TO_SERVER;
+
+ this.isClientToServer = true;
+ this.readAnglesAndData();
+ return;
+ }
+
+ this.readAnglesAndData();
+
+ // extract svc_time
+ this.readSvcTime();
+
+ }
+
+ public boolean isEndOfFile() {
+ return this.isEndOfFile;
+ }
+
+ public boolean isClientToServerPacket() {
+ return this.isClientToServer;
+ }
+
+ public byte[] getOriginalLengthAsByte() {
+ return this.buffer;
+ }
+
+ public byte[] getAngles() {
+ return this.angles;
+ }
+
+ public byte[] getOriginalData() {
+ return this.data;
+ }
+
+ public float getSvcTime() {
+ return this.svcTime;
+ }
+
+ private void readAnglesAndData() {
+ // read angles
+ try {
+ inStream.readFully(angles);
+ } catch (EOFException e) {
+ throw new DemoCutterException("Invalid Demo Packet");
+ } catch (IOException e) {
+ throw new DemoCutterException("Unexpected I/O Exception occurred when processing demo");
+ }
+
+ // read data
+ data = new byte[packetLength];
+ try {
+ inStream.readFully(data);
+ } catch (EOFException e) {
+ throw new DemoCutterException("Invalid Demo Packet");
+ } catch (IOException e) {
+ throw new DemoCutterException("Unexpected I/O Exception occurred when processing demo");
+ }
+ }
+
+ private void readSvcTime() {
+ if (data[0] == 0x07) {
+ ByteBuffer bb = ByteBuffer.allocate(4);
+ bb.put(data, 1, 4);
+ byte[] array = bb.array();
+ this.svcTime = DemoCutterUtils.byteArrayToFloat(array);
+ }
+ }
+}