From d2bde5321773589b459eaaa9013b0488ebc0a0cb Mon Sep 17 00:00:00 2001 From: nathan Date: Mon, 27 Oct 2014 23:28:16 +0100 Subject: [PATCH] Only use a single instance for getting an input stream --- src/dorkbox/util/input/InputConsole.java | 25 +++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/dorkbox/util/input/InputConsole.java b/src/dorkbox/util/input/InputConsole.java index 548dfe9..1f84c34 100644 --- a/src/dorkbox/util/input/InputConsole.java +++ b/src/dorkbox/util/input/InputConsole.java @@ -73,6 +73,19 @@ public class InputConsole { return new String(line); } + private static InputStream wrappedInputStream = new InputStream() { + @Override + public int read() throws IOException { + return consoleProxyReader.read0(); + } + + @Override + public void close() throws IOException { + consoleProxyReader.release0(); + } + }; + + /** return -1 if no data */ public static final int read() { return consoleProxyReader.read0(); @@ -84,17 +97,7 @@ public class InputConsole { } public static InputStream getInputStream() { - return new InputStream() { - @Override - public int read() throws IOException { - return consoleProxyReader.read0(); - } - - @Override - public void close() throws IOException { - consoleProxyReader.release0(); - } - }; + return wrappedInputStream; } public static void echo(boolean enableEcho) {