diff --git a/src/main/java/common/Logger.java b/src/main/java/common/Logger.java new file mode 100644 index 0000000..d8218c9 --- /dev/null +++ b/src/main/java/common/Logger.java @@ -0,0 +1,21 @@ +package common; + +public class Logger { + public static void displayInfo(String message){ + final String BLUE = "\u001B[34m"; + final String RESET = "\u001B[0m"; + System.out.println(BLUE + "Info >>> " + message + RESET); + } + + public static void displayReceived(String message){ + String GREEN = "\u001B[32m"; + String RESET = "\u001B[0m"; + System.out.println(GREEN + "Received >>> " + message + RESET); + } + + public static void displaySent(String message){ + final String RED = "\u001B[31m"; + final String RESET = "\u001B[0m"; + System.out.println(RED + "Sent >>> " + message + RESET); + } +} diff --git a/src/main/java/common/SocketManager.java b/src/main/java/common/SocketManager.java new file mode 100644 index 0000000..b4b4113 --- /dev/null +++ b/src/main/java/common/SocketManager.java @@ -0,0 +1,19 @@ +package common; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.OutputStream; +import java.net.Socket; +import java.nio.charset.StandardCharsets; + +public class SocketManager { + public static void send(Socket socket, String data) throws IOException { + OutputStream output = socket.getOutputStream(); + output.write(String.format("%s\r\n", data).getBytes(StandardCharsets.UTF_8)); + output.flush(); + } + + public static String readResponse(BufferedReader reader) throws IOException { + return reader.readLine(); + } +} diff --git a/src/main/java/step1/Main.java b/src/main/java/step1/Main.java index b003496..4c315e9 100644 --- a/src/main/java/step1/Main.java +++ b/src/main/java/step1/Main.java @@ -13,6 +13,11 @@ import java.security.NoSuchAlgorithmException; import java.security.NoSuchProviderException; import java.security.SecureRandom; import java.util.Base64; +import static common.Logger.displayInfo; +import static common.Logger.displayReceived; +import static common.Logger.displaySent; +import static common.SocketManager.send; +import static common.SocketManager.readResponse; public class Main { @@ -87,34 +92,6 @@ public class Main { } } - public static void displayInfo(String message){ - final String BLUE = "\u001B[34m"; - final String RESET = "\u001B[0m"; - System.out.println(BLUE + "Info >>> " + message + RESET); - } - - public static void displayReceived(String message){ - String GREEN = "\u001B[32m"; - String RESET = "\u001B[0m"; - System.out.println(GREEN + "Received >>> " + message + RESET); - } - - public static void displaySent(String message){ - final String RED = "\u001B[31m"; - final String RESET = "\u001B[0m"; - System.out.println(RED + "Sent >>> " + message + RESET); - } - - public static void send(Socket socket, String data) throws IOException { - OutputStream output = socket.getOutputStream(); - output.write(String.format("%s\r\n", data).getBytes(StandardCharsets.UTF_8)); - output.flush(); - } - - public static String readResponse(BufferedReader reader) throws IOException { - return reader.readLine(); - } - public static SecretKey get3DESKey() throws NoSuchAlgorithmException, NoSuchProviderException { KeyGenerator keyGen = KeyGenerator.getInstance(ALGORITHM, PROVIDER); keyGen.init(new SecureRandom());