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