Code cleanups.
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Tue, 13 Mar 2018 21:03:15 +0000 (22:03 +0100)
committerJérôme Benoit <jerome.benoit@piment-noir.org>
Tue, 13 Mar 2018 21:03:15 +0000 (22:03 +0100)
Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
TD2/client/ClientSimplifie.java
TD2/client/ThreadClientReceive.java
TD2/client/ThreadClientSend.java
TD2/client/ThreadClientoReceive.java
TD2/client/ThreadClientoSend.java

index ace3bd7659961b9f1ee9f2944000636a0cd36ef7..b676c6591c1647a8c736444e0783b12fdfff05a1 100644 (file)
@@ -38,14 +38,13 @@ public class ClientSimplifie {
         // puis établie les chaînages de flot nécessaires
         // pour l'envoi et la reception de messages
         sock = new Socket(adresseIPServeur, portServeur);
-        InputStream IStream = null;
-        IStream = sock.getInputStream();
-        InputStreamReader IMesg = new InputStreamReader(IStream);
-        lecture = new BufferedReader(IMesg);
 
-        OutputStream OStream = null;
-        OStream = sock.getOutputStream();
+        OutputStream OStream = sock.getOutputStream();
         ecriture = new PrintWriter(OStream);
+
+        InputStream IStream = sock.getInputStream();
+        InputStreamReader IMesg = new InputStreamReader(IStream);
+        lecture = new BufferedReader(IMesg);
     }
 
     private void attributesInit() {
index 8be380f42012c55e6787a82aa7d0d69eeeb049d6..74f09c3aff782035c325c2ee2944975479d0107f 100644 (file)
@@ -14,7 +14,7 @@ public class ThreadClientReceive implements Runnable {
             while (!end) {
                 String rline = client.receiveMsg();
                 if (rline.equals(".")) {
-                                       end = true;
+                    end = true;
                 }
                 System.out.println(Thread.currentThread().getName() + " a recu " + rline);
             }
index 9d40e0d6a7effddb01cd3e585fc7a1db0caabd33..42fe7dfd13c723a5cac6c8e09bbfe4cbf7db611c 100644 (file)
@@ -14,26 +14,26 @@ public class ThreadClientSend implements Runnable {
             boolean end = false;
                        while (!end) {
                                String line = userInput.readLine();
-                               if (line.equals(".")) {
+                if (line.equals(".")) {
                     end = true;
                 }
                 client.sendMsg(line);
                 System.out.println(Thread.currentThread().getName() + " a envoye " + line);
             }
-           }
+        }
         catch (IOException e) {
             System.err.println("IOException: " + e);
             e.printStackTrace();
         }
         finally {
             if (userInput != null) {
-                               try {
-                                       userInput.close();
-                               }
-                               catch (IOException e) {
-                                       System.err.println("IOException: " + e);
-                               }
-                       }
+                try {
+                    userInput.close();
+                }
+                catch (IOException e) {
+                    System.err.println("IOException: " + e);
+                }
+            }
         }
     }
 }
index cfad0c9b01229da72427346536f4ff188c494757..177560b4d3643b437fed676da972f9a7ad3058eb 100644 (file)
@@ -14,7 +14,7 @@ public class ThreadClientoReceive implements Runnable {
             while (!end) {
                 Message roMsg = client.receiveoMsg();
                 if (roMsg.getTexte().equals(".")) {
-                                       end = true;
+                    end = true;
                 }
                 System.out.println(Thread.currentThread().getName() + " a recu " + roMsg);
             }
index 53fdeb07addee6917201d274057b4156a39dd0ab..dd8d03b65a1679e2745a5974164fb0248dfadc87 100644 (file)
@@ -5,7 +5,7 @@ import java.util.Random;
 public class ThreadClientoSend implements Runnable {
     private SocketClient client;
     //FIXME: use a random name by thread for now
-    //       should setable
+    //       should be setable
     private String randName;
 
     ThreadClientoSend(SocketClient c) {
@@ -34,9 +34,9 @@ public class ThreadClientoSend implements Runnable {
         try {
             userInput = new BufferedReader(new InputStreamReader(System.in));
             boolean end = false;
-                       while (!end) {
-                               String line = userInput.readLine();
-                               if (line.equals(".")) {
+            while (!end) {
+                String line = userInput.readLine();
+                if (line.equals(".")) {
                     end = true;
                 }
                 Message oMsg = new Message(randName, line, Calendar.getInstance());
@@ -50,13 +50,13 @@ public class ThreadClientoSend implements Runnable {
         }
         finally {
             if (userInput != null) {
-                               try {
-                                       userInput.close();
-                               }
-                               catch (IOException e) {
-                                       System.err.println("IOException: " + e);
-                               }
-                       }
+                try {
+                    userInput.close();
+                }
+                catch (IOException e) {
+                    System.err.println("IOException: " + e);
+                }
+            }
         }
     }
 }