I'm trying to read UTF-16 string from a Socket
. And the point is I don't know its length in bytes before I read first few chars of the string.
So I've opened InputStreamReader
like this:
InputStreamReader reader = new InputStreamReader(inputStream, "UTF-16");
And then I tried to read it char by char.
reader.read();
And it hangs while trying to read the very first char!
In a process of debugging I realized that it looks like InputStreamReader
kinda tries to read WHOLE InputStream
, and then converts it to UTF-16 char sequence. And of course, it goes all the way down to end of string, and it's nothing there, so it just waits for the client to send some more bytes.
Is that really the way InputStreamReader
works? If it is - how can I read a PART of UTF-16 InputStream
, or better one single char, without reaching end of it?