You are viewing a plain text version of this content. The canonical link for it is here.
Posted to httpclient-users@hc.apache.org by "droidin.net" <dr...@droidin.net> on 2009/08/17 20:27:50 UTC

Reading and terminating stream in HttpClient 4

Hi,

Here's what I need to do
1. Read response as a stream 
2. Feed it into SAX-based HTML parser "on the fly"
3. When certain tag is detected - terminate the stream

In other words - I'm reading large documents from which I only need top 5%,
can I do it with HttpClient 4?

Thanks for your suggestions
-- 
View this message in context: http://www.nabble.com/Reading-and-terminating-stream-in-HttpClient-4-tp25011802p25011802.html
Sent from the HttpClient-User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


Re: Reading and terminating stream in HttpClient 4

Posted by Ken Krugler <kk...@transpac.com>.
On Aug 17, 2009, at 11:27am, droidin.net wrote:

> Here's what I need to do
> 1. Read response as a stream
> 2. Feed it into SAX-based HTML parser "on the fly"
> 3. When certain tag is detected - terminate the stream
>
> In other words - I'm reading large documents from which I only need  
> top 5%,
> can I do it with HttpClient 4?

Use the HttpEntity#getContent() method, which returns an  
java.io.InputStream, and pass that to your SAX-based HTML parser.

http://hc.apache.org/httpcomponents-client/tutorial/html/fundamentals.html#d4e122

When you see the tag you need, terminate the request via invoking the  
HttpUriRequest#abort() method.

http://hc.apache.org/httpcomponents-client/tutorial/html/fundamentals.html#d4e285

-- Ken


---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org