Repository navigation
Expand file tree
/
Copy pathEntrance.java
More file actions
61 lines (49 loc) · 2.02 KB
/
Copy pathEntrance.java
File metadata and controls
61 lines (49 loc) · 2.02 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
import org.apache.commons.cli.*;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
public class Entrance {
public static void main(String[] args) throws ParseException, IOException {
Options options = new Options();
options.addOption("h", "help", false, "print this message");
options.addOption("e", "encode", false, "encode omc file");
options.addOption("d", "decode", false, "decode omc file");
options.addOption("i", "input", true, "input file");
options.addOption("o", "output", true, "output file");
CommandLineParser parser = new DefaultParser();
CommandLine cmd = parser.parse(options, args);
File inputFile = null;
File outputFile;
boolean decode = true;
if (cmd.hasOption('h') || args.length == 0) {
HelpFormatter formatter = new HelpFormatter();
formatter.printHelp("java -jar <the jar name> -i cscfeture.xml -o cscfeture_decoded.xml", options);
return;
}
if (cmd.hasOption('i')) {
inputFile = new File(cmd.getOptionValue("i"));
} else {
HelpFormatter formatter = new HelpFormatter();
formatter.printHelp("java -jar <the jar name> -i cscfeture.xml -o cscfeture_decoded.xml", options);
}
if (cmd.hasOption("o")) {
outputFile = new File(cmd.getOptionValue('o'));
} else {
outputFile = new File(inputFile.getParent(), "out_" + inputFile.getName());
}
if (cmd.hasOption('e')) {
decode = false;
}
OmcTextDecoder decoder = new OmcTextDecoder();
byte[] bytes;
if (decode)
bytes = decoder.decode(inputFile);
else {
bytes = decoder.encode(inputFile);
}
FileOutputStream outputStream = new FileOutputStream(outputFile);
outputStream.write(bytes);
outputStream.close();
System.out.println("output " + outputFile.getName() + " success");
}
}