Archived
0

Экранирование IOException при создании Shell

This commit is contained in:
2015-12-12 10:19:26 +03:00
parent dafbbb4978
commit a1c0df622b
2 changed files with 15 additions and 5 deletions

View File

@@ -1,5 +1,5 @@
group = 'ru.dmitriymx'
version = '2.0-SNAPSHOT'
version = '2.1-SNAPSHOT'
apply plugin: 'java'
apply plugin: 'idea'

View File

@@ -30,14 +30,20 @@ public class Shell extends Thread implements Completer {
private Map<String, Command> commandMap = new HashMap<>();
private StringsCompleter stringsCompleter = new StringsCompleter();
public Shell() throws IOException {
public Shell() {
try {
console = new ConsoleReader(System.in, System.err);
console.addCompleter(this);
out = new PrintWriter(console.getOutput());
} catch (IOException e) {
e.printStackTrace(System.err);
}
}
@Override
public synchronized void start() {
if (out == null) return;
try {
this.join();
} catch (InterruptedException e) {
@@ -54,6 +60,8 @@ public class Shell extends Thread implements Completer {
}
public synchronized void shutdown() {
if (out == null) return;
out.print(ConsoleReader.RESET_LINE);
out.flush();
@@ -110,6 +118,8 @@ public class Shell extends Thread implements Completer {
}
public void registerCommand(Command command) {
if (out == null) return;
if (command.getShell() == null) {
command.setShell(this);
}