diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/io/TInputStreamReader.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/io/TInputStreamReader.java index 9ea5ff73d..45c8da9bc 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/io/TInputStreamReader.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/io/TInputStreamReader.java @@ -64,7 +64,7 @@ public class TInputStreamReader extends TReader { @Override public int read() throws TIOException { - if (eof) { + if (eof && outBuffer.end()) { return -1; } if (!outBuffer.end()) { diff --git a/teavm-classlib/src/test/java/org/teavm/classlib/java/lang/io/InputStreamReaderTest.java b/teavm-classlib/src/test/java/org/teavm/classlib/java/lang/io/InputStreamReaderTest.java index b50cdee4d..344b6a941 100644 --- a/teavm-classlib/src/test/java/org/teavm/classlib/java/lang/io/InputStreamReaderTest.java +++ b/teavm-classlib/src/test/java/org/teavm/classlib/java/lang/io/InputStreamReaderTest.java @@ -43,6 +43,21 @@ public class InputStreamReaderTest { } } + @Test + public void readsCharsOneByOne() throws IOException { + String str = "foo bar baz"; + byte[] bytes = new byte[str.length()]; + for (int i = 0; i < str.length(); ++i) { + bytes[i] = (byte)str.charAt(i); + } + ByteArrayInputStream stream = new ByteArrayInputStream(bytes); + InputStreamReader reader = new InputStreamReader(stream, "UTF-8"); + assertEquals('f', reader.read()); + assertEquals('o', reader.read()); + assertEquals('o', reader.read()); + assertEquals(' ', reader.read()); + } + @Test public void readsManyChars() throws IOException { StringBuilder sb = new StringBuilder();