Browse Source

client: stdout to outputStream; fixed intellij refractor error

develop
Robin Thoni 7 years ago
parent
commit
aa4de854b3

+ 1
- 1
src/main/java/com/uqac/rthoni/java_rmi/Main.java View File

60
             usage(name, true);
60
             usage(name, true);
61
         }
61
         }
62
         String mode = args[0];
62
         String mode = args[0];
63
-        if (mode.equals("com/uqac/rthoni/java_rmi/server")) {
63
+        if (mode.equals("server")) {
64
             int port = getPort(name, args[1]);
64
             int port = getPort(name, args[1]);
65
             String sourceDir = args[2];
65
             String sourceDir = args[2];
66
             String classDir = args[3];
66
             String classDir = args[3];

+ 13
- 4
src/main/java/com/uqac/rthoni/java_rmi/client/ClientApplication.java View File

11
  */
11
  */
12
 public class ClientApplication {
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
     public Vector<Command> readInputFile(String file)
22
     public Vector<Command> readInputFile(String file)
15
     {
23
     {
16
         FileInputStream fileInputStream = null;
24
         FileInputStream fileInputStream = null;
43
 
51
 
44
     public void run(String host, int port, String inputFile, String outputFile)
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
         OutputStream outputStream = null;
54
         OutputStream outputStream = null;
49
         if (outputFile.equals("-")) {
55
         if (outputFile.equals("-")) {
50
             outputStream = System.out;
56
             outputStream = System.out;
57
                 System.exit(3);
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
         for (Command command : commands) {
69
         for (Command command : commands) {
61
             runCommand(command, host, port, outputStream);
70
             runCommand(command, host, port, outputStream);
62
         }
71
         }
68
 
77
 
69
     private void runCommand(Command command, String host, int port, OutputStream outputStream)
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
         Socket server = null;
82
         Socket server = null;
74
         try {
83
         try {
75
             server = new Socket(host, port);
84
             server = new Socket(host, port);

Loading…
Cancel
Save