Skip to content

Commit

Permalink
JDK9 compatibility problem
Browse files Browse the repository at this point in the history
  • Loading branch information
gnodet committed Dec 13, 2016
1 parent 0e30d9f commit 7576a62
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/main/java/org/jline/utils/InputStreamReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import java.io.OutputStreamWriter;
import java.io.Reader;
import java.io.UnsupportedEncodingException;
import java.nio.Buffer;
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.charset.Charset;
Expand Down Expand Up @@ -50,7 +51,7 @@ public class InputStreamReader extends Reader {

CharsetDecoder decoder;

ByteBuffer bytes = ByteBuffer.allocate(BUFFER_SIZE);
Buffer bytes = ByteBuffer.allocate(BUFFER_SIZE);

char pending = (char) -1;

Expand Down Expand Up @@ -267,7 +268,7 @@ public int read(char[] buf, int offset, int length) throws IOException {
}

int off = bytes.arrayOffset() + bytes.limit();
int was_red = in.read(bytes.array(), off, 1);
int was_red = in.read(((ByteBuffer) bytes).array(), off, 1);

if (was_red == -1) {
endOfInput = true;
Expand All @@ -279,12 +280,12 @@ public int read(char[] buf, int offset, int length) throws IOException {
}

// decode bytes
result = decoder.decode(bytes, out, false);
result = decoder.decode((ByteBuffer) bytes, out, false);

if (result.isUnderflow()) {
// compact the buffer if no space left
if (bytes.limit() == bytes.capacity()) {
bytes.compact();
((ByteBuffer) bytes).compact();
bytes.limit(bytes.position());
bytes.position(0);
}
Expand All @@ -295,7 +296,7 @@ public int read(char[] buf, int offset, int length) throws IOException {
}

if (result == CoderResult.UNDERFLOW && endOfInput) {
result = decoder.decode(bytes, out, true);
result = decoder.decode((ByteBuffer) bytes, out, true);
decoder.flush(out);
decoder.reset();
}
Expand Down

0 comments on commit 7576a62

Please sign in to comment.