Skip to content

Commit

Permalink
Correct fix for JDK8/JDK9 incompatibility, fixes #64
Browse files Browse the repository at this point in the history
  • Loading branch information
gnodet committed Dec 16, 2016
1 parent bc807c5 commit 6a26a97
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
12 changes: 12 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,18 @@
<activation>
<jdk>9</jdk>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.0</version>
<configuration>
<release>8</release>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>

Expand Down
11 changes: 5 additions & 6 deletions src/main/java/org/jline/utils/InputStreamReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
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 @@ -51,7 +50,7 @@ public class InputStreamReader extends Reader {

CharsetDecoder decoder;

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

char pending = (char) -1;

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

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

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

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

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

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

0 comments on commit 6a26a97

Please sign in to comment.