Reputation: 41
I'm using java's InputStreamReader read() function. When I reach the end of the input stream i'm supposed to get in to my int variable the value of -1, but instead it goes to block. Why don't I get a -1 at the end of the input stream? (i've debugged it letter by letter making sure it is actualy the end of the input and that the connection socket is alive).
Is using the ready() function a good solution by doing:
if (isr.ready())
currCharVal = isr.read();
Thanks in advance, Guy.
Upvotes: 4
Views: 1467
Reputation: 533500
This would happen if the other end is not closing the connection. When the socket is closed, read() will return a -1.
Using ready and available is rather unpredictable in my experience. I would just read(byte[]) until the end is reached and expect the other end to close when finished.
Upvotes: 4