From: Jérôme Benoit Date: Tue, 13 Mar 2018 21:03:15 +0000 (+0100) Subject: Code cleanups. X-Git-Url: https://git.piment-noir.org/?p=TD_SR.git;a=commitdiff_plain;h=6b300998692af2dca53cf1fe97305d27b56430b0 Code cleanups. Signed-off-by: Jérôme Benoit --- diff --git a/TD2/client/ClientSimplifie.java b/TD2/client/ClientSimplifie.java index ace3bd7..b676c65 100644 --- a/TD2/client/ClientSimplifie.java +++ b/TD2/client/ClientSimplifie.java @@ -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() { diff --git a/TD2/client/ThreadClientReceive.java b/TD2/client/ThreadClientReceive.java index 8be380f..74f09c3 100644 --- a/TD2/client/ThreadClientReceive.java +++ b/TD2/client/ThreadClientReceive.java @@ -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); } diff --git a/TD2/client/ThreadClientSend.java b/TD2/client/ThreadClientSend.java index 9d40e0d..42fe7df 100644 --- a/TD2/client/ThreadClientSend.java +++ b/TD2/client/ThreadClientSend.java @@ -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); + } + } } } } diff --git a/TD2/client/ThreadClientoReceive.java b/TD2/client/ThreadClientoReceive.java index cfad0c9..177560b 100644 --- a/TD2/client/ThreadClientoReceive.java +++ b/TD2/client/ThreadClientoReceive.java @@ -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); } diff --git a/TD2/client/ThreadClientoSend.java b/TD2/client/ThreadClientoSend.java index 53fdeb0..dd8d03b 100644 --- a/TD2/client/ThreadClientoSend.java +++ b/TD2/client/ThreadClientoSend.java @@ -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); + } + } } } }