The implementation of stream.readLine() threats char.init as EOF, which is not right because char.init is 255 (which is ÿ in Cyrillic). I believe EOF should be 0.