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;
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)