Hi httpclient-users, I am using HttpClient 4.5.2 / HttpCore 4.4.5 to connect to a streaming endpoint. The endpoint returns chunked records essentially forever. My application consumes these never ending records until an operator signals it to stop. The code looks something like:
try (InputStream r = openHttpConnection(...)) {
while (running) {
Record record = consumeRecord(r);
processRecord(record);
}
}
As you'd expect, when the operator signals stop, the ChunkedInputStream is
closed.
However, the implementation of ChunkedInputStream.close is pretty painful in
this case:
if (!eof && state != CHUNK_INVALID) {
// read and discard the remainder of the message
final byte buff[] = new byte[BUFFER_SIZE];
while (read(buff) >= 0) {
}
}
So my thread sits forever trying to close, discarding more and more data from
the server.
How can I abort this connection cleanly, without needing to read to the end of a
never ending stream of data from the server?
Thanks,
Steven
signature.asc
Description: Message signed with OpenPGP using GPGMail
