From 9b626f890c5b76905fc2c1748bb4767c8389c590 Mon Sep 17 00:00:00 2001 From: Doug MacEachern Date: Tue, 10 May 2005 00:04:33 +0000 Subject: [PATCH] provide pure java getline impl --- .../src/net/hyperic/sigar/util/Getline.java | 26 +++++++++++++++---- 1 file changed, 21 insertions(+), 5 deletions(-) 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)