blob: 1d9bcf4d7877103edea4bc52a030e42c8ba4ffc5 (
plain)
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
|
package cz.crcs.ectester.common.util;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
/**
* @author Jan Jancar johny@neuromancer.sk
*/
public class Util {
public static long convertTime(long nanos, String timeUnit) {
switch (timeUnit) {
default:
case "nano":
return nanos;
case "micro":
return nanos / 1000;
case "milli":
return nanos / 1000000;
}
}
public static int getVersion() {
String version = System.getProperty("java.version");
if (version.startsWith("1.")) {
version = version.substring(2, 3);
} else {
int dot = version.indexOf(".");
if (dot != -1) {
version = version.substring(0, dot);
}
}
return Integer.parseInt(version);
}
public static SecureRandom getRandom(byte[] seed) {
SecureRandom random;
try {
random = SecureRandom.getInstance("SHA1PRNG");
} catch (NoSuchAlgorithmException ignored) {
return null;
}
random.setSeed(seed);
return random;
}
}
|