-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBMSUtil.java
More file actions
119 lines (103 loc) · 3.09 KB
/
BMSUtil.java
File metadata and controls
119 lines (103 loc) · 3.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
package com.kuna.rhythmus.bmsdata;
import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;
public class BMSUtil {
public static void Log(String title, String desc) {
/* your customize part ! */
}
public static String CheckEncoding(byte[] BOM) {
if( (BOM[0] & 0xFF) == 0xEF && (BOM[1] & 0xFF) == 0xBB && (BOM[2] & 0xFF) == 0xBF )
return "UTF-8";
else if( (BOM[0] & 0xFF) == 0xFE && (BOM[1] & 0xFF) == 0xFF )
return "UTF-16BE";
else if( (BOM[0] & 0xFF) == 0xFF && (BOM[1] & 0xFF) == 0xFE )
return "UTF-16LE";
else if( (BOM[0] & 0xFF) == 0x00 && (BOM[1] & 0xFF) == 0x00 &&
(BOM[0] & 0xFF) == 0xFE && (BOM[1] & 0xFF) == 0xFF )
return "UTF-32BE";
else if( (BOM[0] & 0xFF) == 0xFF && (BOM[1] & 0xFF) == 0xFE &&
(BOM[0] & 0xFF) == 0x00 && (BOM[1] & 0xFF) == 0x00 )
return "UTF-32LE";
else
return "ANSI";
}
public static String GetHash(byte[] data) {
String hash = null;
try {
MessageDigest md;
md = MessageDigest.getInstance("MD5");
hash = new BigInteger(1, md.digest( data )).toString(16);
} catch (NoSuchAlgorithmException e) {
BMSUtil.Log("BMSUtil", "Hashing Error!");
e.printStackTrace();
}
return hash;
}
public static boolean IsInteger(String str) {
return Pattern.compile("-?[0-9]+").matcher(str).matches();
}
public static int ExtHexToInt(String hex) {
String sample = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int r = 0;
for (int i=0; i<hex.length(); i++) {
r *= 36;
for (int j=0; j<sample.length(); j++) {
if (hex.substring(i, i+1).compareTo( sample.substring(j, j+1) )==0) {
r += j;
continue;
}
}
}
return r;
}
public static String IntToExtHex(int val) {
String sample = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
return new Character(sample.charAt((int)(val/36))).toString() + new Character(sample.charAt(val%36)).toString();
}
public static int HexToInt(String hex) {
return (int) Long.parseLong(hex, 16);
}
public static String IntTo2Hex(int val) {
return String.format("%02X", val);
}
public static ArrayList<BMSKeyData> cloneKeyArray(List<BMSKeyData> bmsdata) {
ArrayList<BMSKeyData> a = new ArrayList<BMSKeyData>();
for (BMSKeyData bkd: bmsdata) {
a.add(cloneKeyData(bkd));
}
return a;
}
public static BMSKeyData cloneKeyData(BMSKeyData bkd) {
BMSKeyData b = new BMSKeyData();
b.attr = bkd.attr;
b.beat = bkd.beat;
b.key = bkd.key;
b.layernum = bkd.layernum;
b.numerator = bkd.numerator;
b.time = bkd.time;
b.value = bkd.value;
return b;
}
public static List<BMSKeyData> ExtractChannel(List<BMSKeyData> data, int channel) {
ArrayList<BMSKeyData> r = new ArrayList<BMSKeyData>();
for (BMSKeyData b: data) {
if (b.getChannel() == channel) {
r.add(b);
}
}
return r;
}
public static List<BMSKeyData> ExtractLayer(List<BMSKeyData> data, int layer) {
ArrayList<BMSKeyData> r = new ArrayList<BMSKeyData>();
for (BMSKeyData b: data) {
if (b.getLayerNum() == layer) {
r.add(b);
}
}
return r;
}
}