-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathEntrance.java
More file actions
102 lines (83 loc) · 3.06 KB
/
Entrance.java
File metadata and controls
102 lines (83 loc) · 3.06 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
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
import org.apache.commons.cli.*;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.zip.ZipException;
public class Entrance {
private static OmcTextDecoder decoder = new OmcTextDecoder();
public static void main(String[] args) throws ParseException {
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 or dir");
options.addOption("o", "output", true, "output file or dir");
CommandLineParser parser = new DefaultParser();
CommandLine cmd = parser.parse(options, args);
File inputFile;
File outputFile;
boolean decode = true;
if (cmd.hasOption('h') || args.length == 0) {
printHelp(options);
return;
}
if (cmd.hasOption('i')) {
inputFile = new File(cmd.getOptionValue("i"));
} else {
printHelp(options);
return;
}
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;
}
decode(inputFile, outputFile, decode);
}
private static void decode(File in, File out, boolean decode) {
if (in.isDirectory()) {
File[] files = in.listFiles();
if (files != null) {
for (File file : files) {
decode(file, new File(out, file.getName()), decode);
}
}
} else {
decodeFile(in, out, decode);
}
}
private static void decodeFile(File inputFile, File outputFile, boolean decode) {
try {
String path = inputFile.getAbsolutePath();
byte[] bytes;
if (decode)
bytes = decoder.decode(inputFile);
else {
bytes = decoder.encode(inputFile);
}
if (outputFile.exists()) {
outputFile.delete();
}
File parentFile = outputFile.getParentFile();
if (parentFile != null) {
parentFile.mkdirs();
}
outputFile.createNewFile();
FileOutputStream outputStream = new FileOutputStream(outputFile);
outputStream.write(bytes);
outputStream.close();
System.out.println("output " + outputFile.getAbsolutePath() + " success");
} catch (ZipException e) {
//
} catch (IOException e) {
e.printStackTrace();
}
}
private static void printHelp(Options options) {
HelpFormatter formatter = new HelpFormatter();
formatter.printHelp("java -jar <the jar name> -i cscfeture.xml -o cscfeture_decoded.xml", options);
}
}