1 package com.nexuiz.demorecorder.application.democutter;
\r
2 import java.io.DataInputStream;
\r
3 import java.io.EOFException;
\r
4 import java.io.IOException;
\r
5 import java.nio.ByteBuffer;
\r
8 public class DemoPacket {
\r
10 private static final int DEMOMSG_CLIENT_TO_SERVER = 0x80000000;
\r
12 private DataInputStream inStream = null;
\r
13 private boolean isEndOfFile = false;
\r
14 private byte[] buffer = new byte[4]; //contains packet length
\r
15 private byte[] angles = new byte[12];
\r
16 private byte[] data;
\r
17 private int packetLength;
\r
18 private boolean isClientToServer = false;
\r
19 private float svcTime = -1;
\r
21 public DemoPacket(DataInputStream inStream) {
\r
22 this.inStream = inStream;
\r
25 inStream.readFully(buffer);
\r
26 } catch (EOFException e) {
\r
27 this.isEndOfFile = true;
\r
29 } catch (IOException e) {
\r
30 throw new DemoCutterException("Unexpected I/O Exception occurred when processing demo");
\r
33 packetLength = DemoCutterUtils.convertLittleEndian(buffer);
\r
34 if ((packetLength & DEMOMSG_CLIENT_TO_SERVER) != 0) {
\r
35 packetLength = packetLength & ~DEMOMSG_CLIENT_TO_SERVER;
\r
37 this.isClientToServer = true;
\r
38 this.readAnglesAndData();
\r
42 this.readAnglesAndData();
\r
49 public boolean isEndOfFile() {
\r
50 return this.isEndOfFile;
\r
53 public boolean isClientToServerPacket() {
\r
54 return this.isClientToServer;
\r
57 public byte[] getOriginalLengthAsByte() {
\r
61 public byte[] getAngles() {
\r
65 public byte[] getOriginalData() {
\r
69 public float getSvcTime() {
\r
70 return this.svcTime;
\r
73 private void readAnglesAndData() {
\r
76 inStream.readFully(angles);
\r
77 } catch (EOFException e) {
\r
78 throw new DemoCutterException("Invalid Demo Packet");
\r
79 } catch (IOException e) {
\r
80 throw new DemoCutterException("Unexpected I/O Exception occurred when processing demo");
\r
84 data = new byte[packetLength];
\r
86 inStream.readFully(data);
\r
87 } catch (EOFException e) {
\r
88 throw new DemoCutterException("Invalid Demo Packet");
\r
89 } catch (IOException e) {
\r
90 throw new DemoCutterException("Unexpected I/O Exception occurred when processing demo");
\r
94 private void readSvcTime() {
\r
95 if (data[0] == 0x07) {
\r
96 ByteBuffer bb = ByteBuffer.allocate(4);
\r
98 byte[] array = bb.array();
\r
99 this.svcTime = DemoCutterUtils.byteArrayToFloat(array);
\r