Skip to content

Commit

Permalink
Fix ByteBuffer incompatibilities with jdk9, fixes #299
Browse files Browse the repository at this point in the history
  • Loading branch information
gnodet committed Mar 8, 2019
1 parent a063022 commit 12b98d9
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/main/java/jline/internal/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 @@ -68,7 +69,7 @@ public InputStreamReader(InputStream in) {
decoder = Charset.defaultCharset().newDecoder().onMalformedInput(
CodingErrorAction.REPLACE).onUnmappableCharacter(
CodingErrorAction.REPLACE);
bytes.limit(0);
((Buffer) bytes).limit(0);
}

/**
Expand Down Expand Up @@ -101,7 +102,7 @@ public InputStreamReader(InputStream in, final String enc)
throw (UnsupportedEncodingException)
new UnsupportedEncodingException(enc).initCause(e);
}
bytes.limit(0);
((Buffer) bytes).limit(0);
}

/**
Expand All @@ -118,7 +119,7 @@ public InputStreamReader(InputStream in, CharsetDecoder dec) {
dec.averageCharsPerByte();
this.in = in;
decoder = dec;
bytes.limit(0);
((Buffer) bytes).limit(0);
}

/**
Expand All @@ -136,7 +137,7 @@ public InputStreamReader(InputStream in, Charset charset) {
decoder = charset.newDecoder().onMalformedInput(
CodingErrorAction.REPLACE).onUnmappableCharacter(
CodingErrorAction.REPLACE);
bytes.limit(0);
((Buffer) bytes).limit(0);
}

/**
Expand Down Expand Up @@ -262,7 +263,7 @@ public int read(char[] buf, int offset, int length) throws IOException {
} else if (was_red == 0) {
break;
}
bytes.limit(bytes.limit() + was_red);
((Buffer) bytes).limit(bytes.limit() + was_red);
needInput = false;
}

Expand All @@ -273,8 +274,8 @@ public int read(char[] buf, int offset, int length) throws IOException {
// compact the buffer if no space left
if (bytes.limit() == bytes.capacity()) {
bytes.compact();
bytes.limit(bytes.position());
bytes.position(0);
((Buffer) bytes).limit(bytes.position());
((Buffer) bytes).position(0);
}
needInput = true;
} else {
Expand Down

0 comments on commit 12b98d9

Please sign in to comment.