provide pure java getline impl

This commit is contained in:
Doug MacEachern 2005-05-10 00:04:33 +00:00
parent 3755efe551
commit 9b626f890c
1 changed files with 21 additions and 5 deletions

View File

@ -1,6 +1,8 @@
package net.hyperic.sigar.util; package net.hyperic.sigar.util;
import java.io.BufferedReader;
import java.io.IOException; import java.io.IOException;
import java.io.InputStreamReader;
import java.io.EOFException; import java.io.EOFException;
import java.io.File; import java.io.File;
@ -13,6 +15,11 @@ import java.io.File;
*/ */
public class Getline { public class Getline {
private static boolean useNative =
! "false".equals(System.getProperty("sigar.getline.native"));
private BufferedReader in = null;
private String prompt = "> "; private String prompt = "> ";
public Getline() { } public Getline() { }
@ -49,12 +56,21 @@ public class Getline {
public String getLine(String prompt, boolean addToHistory) public String getLine(String prompt, boolean addToHistory)
throws IOException, EOFException { throws IOException, EOFException {
//XXX provide pure-java fallback if (useNative) {
String line = getline(prompt); String line = getline(prompt);
if (addToHistory) { if (addToHistory) {
addToHistory(line); 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) public void initHistoryFile(File file)