On 1 Jan 2013, at 11:32 AM, Jean-Marc Spaggiari <[email protected]> wrote:
> If I do response.getEntity() is it going to give the control back only
> when ALL the data will be retreived?
Positively not. We have the same problem and we solve it like this:
httpGet.reset();
httpGet.setURI( url );
try {
httpClient.execute( httpGet, new ResponseHandler<Void>() {
@Override
public Void handleResponse( HttpResponse response ) throws
ClientProtocolException, IOException {
// Do stuff with your response (headers, etc.)
HttpEntity entity = response.getEntity();
if ( entity != null ) {
final InputStream content = entity.getContent();
final InputStream limitedStream =
ByteStreams.limit( content, maxResponseBodyLength );
// Do stuff with the limited stream, reading it
until EOF.
if ( content.read() != -1 ) httpGet.abort();
}
return null;
}} );
}
catch( IOException e ) {
// Process exception
}
ByteStreams from Google Guava.
Ciao,
seba
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]