provide pure java getline impl
This commit is contained in:
parent
3755efe551
commit
9b626f890c
|
@ -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,13 +56,22 @@ public class Getline {
|
|||
public String getLine(String prompt, boolean addToHistory)
|
||||
throws IOException, EOFException {
|
||||
|
||||
//XXX provide pure-java fallback
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
public void initHistoryFile(File file)
|
||||
throws IOException {
|
||||
|
|
Loading…
Reference in New Issue