diff --git a/bindings/java/src/net/hyperic/sigar/util/Getline.java b/bindings/java/src/net/hyperic/sigar/util/Getline.java index b5b1e771..eb86a19e 100644 --- a/bindings/java/src/net/hyperic/sigar/util/Getline.java +++ b/bindings/java/src/net/hyperic/sigar/util/Getline.java @@ -1,6 +1,8 @@ package net.hyperic.sigar.util; +import java.io.BufferedReader; import java.io.IOException; +import java.io.InputStreamReader; import java.io.EOFException; import java.io.File; @@ -13,6 +15,11 @@ import java.io.File; */ public class Getline { + private static boolean useNative = + ! "false".equals(System.getProperty("sigar.getline.native")); + + private BufferedReader in = null; + private String prompt = "> "; public Getline() { } @@ -49,12 +56,21 @@ public class Getline { public String getLine(String prompt, boolean addToHistory) throws IOException, EOFException { - //XXX provide pure-java fallback - String line = getline(prompt); - if (addToHistory) { - addToHistory(line); + if (useNative) { + String line = getline(prompt); + if (addToHistory) { + addToHistory(line); + } + return line; + } + else { + if (this.in == null) { + this.in = + new BufferedReader(new InputStreamReader(System.in)); + } + System.out.print(prompt); + return this.in.readLine(); } - return line; } public void initHistoryFile(File file)