Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions src/main/java/jline/ConsoleReaderInputStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public boolean hasMoreElements() {

private static class ConsoleLineInputStream extends InputStream {
private final ConsoleReader reader;
private String line = null;
private byte[] line;
private int index = 0;
private boolean eol = false;
protected boolean wasNull = false;
Expand All @@ -89,20 +89,31 @@ public int read() throws IOException {
}

if (line == null) {
line = reader.readLine();
//reader will read in correctly with proper encoding
String sline = reader.readLine();

if (sline == null) {
line = null;
} else {
//TODO use same encoding as Unix/WindowsTerminal or ConsoleReader
line = sline.getBytes();
}
}

if (line == null) {
wasNull = true;
return -1;
}

if (index >= line.length()) {
if (index >= line.length) {
eol = true;
return '\n'; // lines are ended with a newline
}

return line.charAt(index++);
//InputStreams work with bytes, so we can't
//return a char that may not fit into one byte
//for multibyte chars, this will return each byte in turn
return line[index++];
}
}
}