Monica视频监控处理程序
add
xc
2021-08-16 209c26e699ba9b5f12855772b59618ce1a423da9
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
package com.hbbh.adapter.app;
 
 
import com.google.common.collect.Lists;
 
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
 
/**
 * 设置 实时数据库环境程序
 */
public class RTDBPath {
 
 
    public static void main(String[] args) {
        printLibrary();
    }
 
    private static final String key = "java.library.path";
    //Windows
    private static final String regex_win = ";";
    // mac
    private static final String regex_mac = ":";
 
    private static final String _mac = "mac";
    private static final String _windows = "windows";
 
    private static final String os_name = "os.name";
 
 
    public static void printLibrary() {
        String os = chooseOS();
        setSystemPath(os);
 
        String osName = System.getProperty(os_name).toLowerCase();
 
        System.out.println("当前运行操作系统:" + osName);
        System.out.println("-------------- 引入第三方包环境变量之前 --- Before -------------- ");
        String propertyBefore = System.getProperty(key);
        if (propertyBefore.contains(regex_win)) {
            String[] split = propertyBefore.split(regex_win);
            for (String s : split) {
                System.out.println(s);
            }
        } else {
            System.out.println(propertyBefore);
        }
        System.out.println("------------------------------------------ ");
    }
 
    //需要在 resources 下创建 depend 文件夹 将实时库依赖包放进去
    private static String dependPath = Thread.currentThread().getContextClassLoader().getResource("depend").getPath();
 
    private static void setSystemPath(String os) {
        String propertyBefore = System.getProperty(key);
 
        switch (os) {
            case _windows:
                String[] splitWin = propertyBefore.split(regex_win);
                List<String> wins = Arrays.asList(splitWin);
                List<String> winList = Lists.newArrayList(wins);
                winList.add(dependPath);
                spliceWin(wins);
                break;
            case _mac:
                String[] splitMac = propertyBefore.split(regex_mac);
                List<String> macs = Arrays.asList(splitMac);
                List<String> macList = Lists.newArrayList(macs);
                macList.add(dependPath);
                spliceMac(macList);
                break;
            default:
                throw new RuntimeException("当前操作系统不识别");
        }
    }
 
    private static void spliceMac(List<String> macList) {
        StringBuilder sb=new StringBuilder();
        for (int i = 0; i < macList.size(); i++) {
            if (i==(macList.size()-1)){
                sb.append(macList.get(i));
            }else {
                sb.append(macList.get(i));
                sb.append(regex_mac);
            }
        }
        System.setProperty(key, sb.toString());
    }
 
    private static void spliceWin(List<String> winList) {
        StringBuilder sb=new StringBuilder();
        for (int i = 0; i < winList.size(); i++) {
            if (i==(winList.size()-1)){
                sb.append(winList.get(i));
            }else {
                sb.append(winList.get(i));
                sb.append(regex_win);
            }
        }
        System.setProperty(key, sb.toString());
    }
 
    private static String chooseOS() {
        String osName = System.getProperty(os_name).toLowerCase();
        if (osName.contains(_mac)) {
            //throw new RuntimeException("警告:当前程序必须在Windows环境下执行");
        } else if (osName.contains(_windows)) {
            return _windows;
        } else {
            throw new RuntimeException("当前操作系统不识别");
        }
 
        throw new RuntimeException("当前操作系统不识别");
    }
}