Browse Source

refactor input output stream handling

feature-implement-menu-control
binsky 3 years ago
parent
commit
138b9a02bf
  1. 20
      src/main/java/PasswordManager.java

20
src/main/java/PasswordManager.java

@ -7,24 +7,29 @@ import java.util.Scanner;
public class PasswordManager implements PasswordManagerInterface { public class PasswordManager implements PasswordManagerInterface {
boolean running = true; boolean running = true;
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
public static void main(String[] args) { public static void main(String[] args) {
PasswordManager pm = new PasswordManager(); PasswordManager pm = new PasswordManager();
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
while (pm.running) { while (pm.running) {
pm.showMenu(inputStream, outputStream);
pm.showMenu(null, null);
} }
System.exit(0); System.exit(0);
} }
public PasswordManager() { public PasswordManager() {
System.out.println("Hello World");
try {
outputStream.write("Hello World\n".getBytes(StandardCharsets.UTF_8));
} catch (IOException e) {
e.printStackTrace();
}
} }
@Override @Override
public void listVaults() { public void listVaults() {
} }
@Override @Override
@ -34,6 +39,13 @@ public class PasswordManager implements PasswordManagerInterface {
@Override @Override
public void showMenu(InputStream inputStream, OutputStream outputStream) { public void showMenu(InputStream inputStream, OutputStream outputStream) {
if (inputStream == null) {
inputStream = this.inputStream;
}
if (outputStream == null) {
outputStream = this.outputStream;
}
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
Scanner scan = new Scanner(inputStream); Scanner scan = new Scanner(inputStream);
running = true; running = true;

Loading…
Cancel
Save