]> icculus.org git repositories - divverent/nexuiz.git/blob - misc/tools/NexuizDemoRecorder/src/main/java/com/nexuiz/demorecorder/application/democutter/DemoCutterUtils.java
move NDR main program into subfolder
[divverent/nexuiz.git] / misc / tools / NexuizDemoRecorder / src / main / java / com / nexuiz / demorecorder / application / democutter / DemoCutterUtils.java
1 package com.nexuiz.demorecorder.application.democutter;\r
2 import java.nio.ByteBuffer;\r
3 import java.nio.ByteOrder;\r
4 \r
5 \r
6 public class DemoCutterUtils {\r
7 \r
8         public static float byteArrayToFloat(byte[] array) {\r
9                 byte[] tmp = new byte[4];\r
10                 System.arraycopy(array, 0, tmp, 0, 4);\r
11                 int accum = 0;\r
12                 int i = 0;\r
13                 for (int shiftBy = 0; shiftBy < 32; shiftBy += 8) {\r
14                         accum |= ((long) (tmp[i++] & 0xff)) << shiftBy;\r
15                 }\r
16                 return Float.intBitsToFloat(accum);\r
17         }\r
18 \r
19         public static byte[] convertLittleEndian(int i) {\r
20                 ByteBuffer bb = ByteBuffer.allocate(4);\r
21                 bb.order(ByteOrder.LITTLE_ENDIAN);\r
22                 bb.putInt(i);\r
23                 return bb.array();\r
24         }\r
25 \r
26         public static byte[] mergeByteArrays(byte[] array1, byte[] array2) {\r
27                 ByteBuffer bb = ByteBuffer.allocate(array1.length + array2.length);\r
28                 bb.put(array1);\r
29                 bb.put(array2);\r
30                 return bb.array();\r
31         }\r
32 \r
33         public static int convertLittleEndian(byte[] b) {\r
34                 ByteBuffer bb = ByteBuffer.allocate(4);\r
35                 bb.order(ByteOrder.LITTLE_ENDIAN);\r
36                 bb.put(b);\r
37                 bb.position(0);\r
38                 return bb.getInt();\r
39         }\r
40 }\r