Fixes InputStreamReader one-by-one read

This commit is contained in:
konsoletyper 2014-02-24 19:53:21 +04:00
parent 8cbb6477cb
commit 744033b118
2 changed files with 16 additions and 1 deletions

View File

@ -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()) {

View File

@ -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();