From c93929ef03d760247a5e8c18c01e492286937699 Mon Sep 17 00:00:00 2001 From: Valentin Spiroski Date: Mon, 5 Feb 2024 13:51:33 +0100 Subject: [PATCH] refactoring: identation run() --- src/main/java/ClientHandler.java | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/main/java/ClientHandler.java b/src/main/java/ClientHandler.java index db9059f..7b96316 100644 --- a/src/main/java/ClientHandler.java +++ b/src/main/java/ClientHandler.java @@ -16,27 +16,32 @@ public class ClientHandler implements Runnable { @Override public void run() { + try { - fromClientReader = new BufferedReader(new InputStreamReader(connectionToClient.getInputStream())); - toClientWriter = new PrintWriter(new OutputStreamWriter(connectionToClient.getOutputStream())); + fromClientReader = new BufferedReader (new InputStreamReader(connectionToClient.getInputStream())); + toClientWriter = new PrintWriter (new OutputStreamWriter(connectionToClient.getOutputStream())); chatServer.broadcastMessage(name + " connected."); String message = fromClientReader.readLine(); while (message!=null) { chatServer.broadcastMessage(name + ": " + message); message = fromClientReader.readLine(); - } - } catch (IOException e) { - throw new RuntimeException(e); - - } finally { + } + } + + catch (IOException e) { + throw new RuntimeException(e); + } + + finally { //chatServer.removeClient(this); chatServer.broadcastMessage(name + " disconnected."); if (fromClientReader != null) { try { fromClientReader.close(); - } catch (IOException e){ + } + catch (IOException e){ e.printStackTrace(); } } @@ -50,5 +55,4 @@ public class ClientHandler implements Runnable { toClientWriter.println(message); toClientWriter.flush(); } - }