From 138b9a02bf045cf6aa6f6f99b8204fa9f41de82f Mon Sep 17 00:00:00 2001 From: binsky Date: Mon, 24 Jan 2022 20:44:57 +0100 Subject: [PATCH] refactor input output stream handling --- src/main/java/PasswordManager.java | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/main/java/PasswordManager.java b/src/main/java/PasswordManager.java index a8cec33..8c8b7dd 100644 --- a/src/main/java/PasswordManager.java +++ b/src/main/java/PasswordManager.java @@ -7,24 +7,29 @@ import java.util.Scanner; public class PasswordManager implements PasswordManagerInterface { boolean running = true; + InputStream inputStream = System.in; + OutputStream outputStream = System.out; public static void main(String[] args) { PasswordManager pm = new PasswordManager(); - InputStream inputStream = System.in; - OutputStream outputStream = System.out; while (pm.running) { - pm.showMenu(inputStream, outputStream); + pm.showMenu(null, null); } System.exit(0); } public PasswordManager() { - System.out.println("Hello World"); + try { + outputStream.write("Hello World\n".getBytes(StandardCharsets.UTF_8)); + } catch (IOException e) { + e.printStackTrace(); + } } @Override public void listVaults() { + } @Override @@ -34,6 +39,13 @@ public class PasswordManager implements PasswordManagerInterface { @Override public void showMenu(InputStream inputStream, OutputStream outputStream) { + if (inputStream == null) { + inputStream = this.inputStream; + } + if (outputStream == null) { + outputStream = this.outputStream; + } + StringBuilder sb = new StringBuilder(); Scanner scan = new Scanner(inputStream); running = true;