Originally posted by Tahir Akram:
This exception occur when buffer reader contain last record. Instead of after reading last line, it should attempt to read next line which will be EOF, but while reading last one this exception occur.
[/CODE]
Firstly, the reason why BufferedReader is not keeping up to the contract of readLine().
As you can see from the stack trace, ChunkedInputStream.readAheadBlocking is throwing an EOFException and this makes HttpURLConnection$HttpInputStream.read break the contract of read( i.e. read should return -1 when EOF is reached.)
Since, the buffered reader relies on the contract of read to abide by the contract of readline(), readline also fails.
Solution:
I think the straight forward solution will be, not to read using BufferedReader but one byte at a time and put the read in a try-catch for EOFException.
Other way is to put a mark at the position where the last line ended i.e. put a mark right after readLine() returns. In case you get an EOFException read one byte at a time from the last mark. (This sounds like a feasible solution, i have not tried though.)
NOTE: Marking will require a readaheadlimit, providing a value for which will be a little difficult as it depends on the max bytes in a line.