mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-22 08:14:09 -08:00
classlib: fix issue in InputStreamReader
This commit is contained in:
parent
3ac0078e2a
commit
c5768e07bc
|
@ -110,8 +110,11 @@ public class TInputStreamReader extends TReader {
|
|||
if (!inBuffer.hasRemaining() && !fillReadBuffer()) {
|
||||
break;
|
||||
}
|
||||
if (decoder.decode(inBuffer, outBuffer, streamEof).isOverflow()) {
|
||||
var result = decoder.decode(inBuffer, outBuffer, streamEof);
|
||||
if (result.isOverflow()) {
|
||||
break;
|
||||
} else if (result.isUnderflow()) {
|
||||
fillReadBuffer();
|
||||
}
|
||||
}
|
||||
if (!inBuffer.hasRemaining() && streamEof && decoder.flush(outBuffer).isUnderflow()) {
|
||||
|
|
|
@ -17,8 +17,10 @@ package org.teavm.classlib.java.io;
|
|||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.teavm.junit.TeaVMTestRunner;
|
||||
|
@ -78,4 +80,22 @@ public class InputStreamReaderTest {
|
|||
assertEquals(str.charAt(i), chars[i]);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void underflowWhileFillingBuffer() throws IOException {
|
||||
var bos = new ByteArrayOutputStream();
|
||||
bos.write(0x24);
|
||||
for (var i = 0; i < 20000; ++i) {
|
||||
bos.write(0xC2);
|
||||
bos.write(0xA2);
|
||||
}
|
||||
|
||||
var bis = new ByteArrayInputStream(bos.toByteArray());
|
||||
var reader = new InputStreamReader(bis, StandardCharsets.UTF_8);
|
||||
assertEquals(0x24, reader.read());
|
||||
for (var i = 0; i < 20000; ++i) {
|
||||
assertEquals(0xA2, reader.read());
|
||||
}
|
||||
assertEquals(-1, reader.read());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user