对jar或者war进行加密解密
whycxzp
2021-12-22 f6b935781bcb43faea7aa894ce3a55873769efb3
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
package com.whyc.util;
 
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
/**
 * 命令行参数解析工具
 *
 * @author perry
 */
public class CmdLineOption {
    /**
     * option
     */
    private List<String> options = new ArrayList<>();
    /**
     * hasArgs
     */
    private List<Boolean> hasArgs = new ArrayList<>();
    /**
     * descriptions
     */
    private List<String> descriptions = new ArrayList<>();
    /**
     * option and values
     */
    private Map<String, List<String>> optionsMap = new HashMap<>();
 
    /**
     * Add an option that only contains a short-name.
     *
     * <p>
     * It may be specified as requiring an argument.
     * </p>
     *
     * @param opt         Short single-character name of the option.
     * @param hasArg      flag signally if an argument is required after this option
     * @param description Self-documenting description
     * @return the resulting Options instance
     */
    public CmdLineOption addOption(String opt, boolean hasArg, String description) {
        opt = resolveOption(opt);
        if (!options.contains(opt)) {
            options.add(opt);
            hasArgs.add(hasArg);
            descriptions.add(description);
        }
        return this;
    }
 
    /**
     * Parse the arguments according to the specified options.
     *
     * @param arguments the command line arguments
     * @return CmdLineOption
     */
    public CmdLineOption parse(String[] arguments) {
        int optIndex = -1;
        for (int i = 0; i < arguments.length; i++) {
            String arg = arguments[i];
 
            if (arg.startsWith("-") || arg.startsWith("--")) {
                arg = resolveOption(arg);
 
                //check last option hasArg
                if (optIndex > -1 && hasArgs.get(optIndex)) {
                    String lastOption = options.get(optIndex);
                    if (optionsMap.get(lastOption).size() == 0) {
                        throw new IllegalArgumentException("Missing argument for option: " + lastOption);
                    }
                }
 
                optIndex = options.indexOf(arg);
                if (optIndex < 0) {
                    throw new IllegalArgumentException("Unrecognized option: " + arguments[i]);
                }
                optionsMap.put(arg, new ArrayList<>());
            } else if (optIndex > -1) {
                String option = options.get(optIndex);
                optionsMap.get(option).add(arg);
            }
        }
        return this;
    }
 
    /**
     * Retrieve the first argument, if any, of this option.
     *
     * @param opt the name of the option
     * @return Value of the argument if option is set, and has an argument,
     * otherwise null.
     */
    public String getOptionValue(String opt) {
        return getOptionValue(opt, null);
    }
 
    /**
     * Retrieve the first argument, if any, of this option.
     *
     * @param opt the name of the option
     * @param dv  default value
     * @return Value of the argument if option is set, and has an argument,
     * otherwise null.
     */
    public String getOptionValue(String opt, String dv) {
        String[] values = getOptionValues(opt);
        return (values == null) ? dv : values[0];
    }
 
    /**
     * Retrieves the array of values, if any, of an option.
     *
     * @param opt string name of the option
     * @return Values of the argument if option is set, and has an argument,
     * otherwise null.
     */
    public String[] getOptionValues(String opt) {
        List<String> values = optionsMap.get(resolveOption(opt));
        return (values == null || values.isEmpty()) ? null : values.toArray(new String[values.size()]);
    }
 
    /**
     * Query to see if an option has been set.
     *
     * @param opt Short name of the option
     * @return true if set, false if not
     */
    public boolean hasOption(String opt) {
        return optionsMap.keySet().contains(resolveOption(opt));
    }
 
    /**
     * Remove the hyphens from the beginning of <code>str</code> and
     * return the new String.
     *
     * @param str The string from which the hyphens should be removed.
     * @return the new String.
     */
    private static String resolveOption(String str) {
        if (str == null) {
            return null;
        }
        if (str.startsWith("--")) {
            return str.substring(2, str.length());
        } else if (str.startsWith("-")) {
            return str.substring(1, str.length());
        }
 
        return str;
    }
}