At the first loop while stops and waits for console input at the incomStr = view.read();
but at the second loop it doesn't stop, reads null
and goes on.
Why is it happening?
public void mainDialogueHolder() {//todo
setCmdState(CmdLineState.WAIT);
view.write("Hello, user!");
view.write("Please, type `help` for list available commands. ");
while (getCMDState().equals(CmdLineState.WAIT)){
String incomStr;
incomStr = view.read();//implementation is below
readCmd(incomStr);
}
}
Implementation of view
public class Console implements View {
@Override
public void write(String message) {
System.out.println(message);
}
@Override
public String read() {
try (
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))
){
return reader.readLine();
} catch (IOException ex) {
System.out.println(ex.getMessage());
return null;
}
}
}