开发者

Unable to close http streaming on wrong response

My apache HTTP client is reading data from a server which is sending HTTP streaming (in form of chunked data) to us.

I have a input stream and Buffered Reader to get data, and reading this data using Buffered Data readLine method.

InputStream inputStream = httpEntity.getContent();
br= new BufferedReader(new InputStreamReader(inputStream));

while ((line = br.readLine()) != null) 

I want to close the connection if I get a wrong response from server.

For this I am creating a timertask at a time interval to close my connection. I am parsing the response each time I receive it to check if the response is correct, if the re开发者_运维知识库sponse is correct then I reset the timetask. If I find a wrong response in that case I don't reset the timertask (and let the timertask be executed to the time it was previously set for)

I want to know if using unbuffered I/O can help? or I need some other approach?

Problem I see is since the connection is open, my timertask is unable to close the connection. inputStream.close or bufferReader.close both are not able to execute (seem to infinitely wait)


BufferReader.close() will only close the inputStream, which in turn will call inputStream.close(). According to the java api InputStream.close() does nothing. You need to close the socket, or whatever it is that you are abstracting by httpEntity.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜