forked from docker-java/docker-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAvroToolMain.java
More file actions
123 lines (111 loc) · 3.72 KB
/
Copy pathAvroToolMain.java
File metadata and controls
123 lines (111 loc) · 3.72 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package pi.docker;
import org.apache.avro.tool.*;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Map;
import java.util.TreeMap;
/** Command-line driver.*/
public class AvroToolMain {
/**
* Available tools, initialized in constructor.
*/
final Map<String, Tool> tools;
int maxLen = 0;
AvroToolMain() {
tools = new TreeMap<String, Tool>();
for (Tool tool : new Tool[] {
new CatTool(),
new SpecificCompilerTool(),
new InduceSchemaTool(),
new JsonToBinaryFragmentTool(),
new BinaryFragmentToJsonTool(),
new CreateRandomFileTool(),
new DataFileReadTool(),
new DataFileWriteTool(),
new DataFileGetMetaTool(),
new DataFileGetSchemaTool(),
new DataFileRepairTool(),
new IdlTool(),
new IdlToSchemataTool(),
new RecodecTool(),
new ConcatTool(),
new RpcReceiveTool(),
new RpcSendTool(),
new RpcProtocolTool(),
new FromTextTool(),
new ToTextTool(),
new ToTrevniTool(),
new TetherTool(),
new TrevniCreateRandomTool(),
new TrevniMetadataTool(),
new TrevniToJsonTool()
}) {
Tool prev = tools.put(tool.getName(), tool);
if (prev != null) {
throw new AssertionError(
"Two tools with identical names: " + tool + ", " + prev);
}
maxLen = Math.max(tool.getName().length(), maxLen);
}
}
public static void main(String[] args) throws Exception {
int rc = new AvroToolMain().run(args);
System.exit(rc);
}
/**
* Delegates to tool specified on the command-line.
*/
private int run(String[] args) throws Exception {
if (args.length != 0) {
Tool tool = tools.get(args[0]);
if (tool != null) {
return tool.run(
System.in, System.out, System.err, Arrays.asList(args).subList(1, args.length));
}
}
System.err.print("Version ");
printStream(Main.class.getClassLoader().getResourceAsStream("VERSION.txt"));
System.err.print(" of ");
printHead(Main.class.getClassLoader().getResourceAsStream("META-INF/NOTICE"), 5);
System.err.println("----------------");
System.err.println("Available tools:");
for (Tool k : tools.values()) {
System.err.printf("%" + maxLen + "s %s\n", k.getName(), k.getShortDescription());
}
return 1;
}
private static void printStream(InputStream in) throws Exception {
byte[] buffer = new byte[1024];
for (int i = in.read(buffer); i != -1; i = in.read(buffer))
System.err.write(buffer, 0, i);
}
private static void printHead(InputStream in, int lines) throws Exception {
BufferedReader r = new BufferedReader(new InputStreamReader(in));
for (int i = 0; i < lines; i++) {
String line = r.readLine();
if (line == null) {
break;
}
System.err.println(line);
}
}
}