|
@@ -11,6 +11,14 @@ import java.util.Vector;
|
11
|
11
|
*/
|
12
|
12
|
public class ClientApplication {
|
13
|
13
|
|
|
14
|
+ public void format(OutputStream outputStream, String format, Object... objs)
|
|
15
|
+ {
|
|
16
|
+ try {
|
|
17
|
+ outputStream.write(String.format(format, objs).getBytes());
|
|
18
|
+ } catch (IOException e) {
|
|
19
|
+ }
|
|
20
|
+ }
|
|
21
|
+
|
14
|
22
|
public Vector<Command> readInputFile(String file)
|
15
|
23
|
{
|
16
|
24
|
FileInputStream fileInputStream = null;
|
|
@@ -43,8 +51,6 @@ public class ClientApplication {
|
43
|
51
|
|
44
|
52
|
public void run(String host, int port, String inputFile, String outputFile)
|
45
|
53
|
{
|
46
|
|
- System.out.format("Reading input file %s...\n", inputFile);
|
47
|
|
- Vector<Command> commands = readInputFile(inputFile);
|
48
|
54
|
OutputStream outputStream = null;
|
49
|
55
|
if (outputFile.equals("-")) {
|
50
|
56
|
outputStream = System.out;
|
|
@@ -57,6 +63,9 @@ public class ClientApplication {
|
57
|
63
|
System.exit(3);
|
58
|
64
|
}
|
59
|
65
|
}
|
|
66
|
+
|
|
67
|
+ format(outputStream, "Reading input file %s...\n", inputFile);
|
|
68
|
+ Vector<Command> commands = readInputFile(inputFile);
|
60
|
69
|
for (Command command : commands) {
|
61
|
70
|
runCommand(command, host, port, outputStream);
|
62
|
71
|
}
|
|
@@ -68,8 +77,8 @@ public class ClientApplication {
|
68
|
77
|
|
69
|
78
|
private void runCommand(Command command, String host, int port, OutputStream outputStream)
|
70
|
79
|
{
|
71
|
|
- System.out.format("Running command %s...\n", command.getCommandName());
|
72
|
|
- System.out.format("Connecting to %s:%d...\n", host, port);
|
|
80
|
+ format(outputStream, "Running command %s...\n", command.getCommandName());
|
|
81
|
+ format(outputStream, "Connecting to %s:%d...\n", host, port);
|
73
|
82
|
Socket server = null;
|
74
|
83
|
try {
|
75
|
84
|
server = new Socket(host, port);
|