-
Notifications
You must be signed in to change notification settings - Fork 331
Expand file tree
/
Copy pathSystemUtils.java
More file actions
53 lines (45 loc) · 1.31 KB
/
SystemUtils.java
File metadata and controls
53 lines (45 loc) · 1.31 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
package datadog.trace.bootstrap;
public final class SystemUtils {
private SystemUtils() {}
public static String tryGetEnv(String envVar) {
return getEnvOrDefault(envVar, null);
}
public static String getEnvOrDefault(String envVar, String defaultValue) {
try {
return System.getenv(envVar);
} catch (SecurityException e) {
return defaultValue;
}
}
public static String tryGetProperty(String property) {
try {
return System.getProperty(property);
} catch (SecurityException e) {
return null;
}
}
public static String trySetProperty(String property, String value) {
try {
return System.setProperty(property, value);
} catch (SecurityException e) {
return null;
}
}
public static String getPropertyOrDefault(String property, String defaultValue) {
try {
return System.getProperty(property, defaultValue);
} catch (SecurityException e) {
return defaultValue;
}
}
private static String toEnvVar(String string) {
return string.replace('.', '_').replace('-', '_').toUpperCase();
}
public static String getPropertyOrEnvVar(String property) {
String envVarValue = System.getenv(toEnvVar(property));
if (envVarValue != null) {
return envVarValue;
}
return System.getProperty(property);
}
}