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