hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Oleg Kalnichevski <ol...@apache.org>
Subject Re: HttpEntity.writeTo vs. EntityUtils.toByteArray
Date Mon, 26 Oct 2009 16:16:37 GMT
Charles Fran├žois Rey wrote:
> Hi,
> 
> I receive gzip-compressed content from a server, and I handle it as 
> suggested in the ClientGZipContentCompression.java example, i.e. via 
> request and response interceptors. This is all working fine.
> 
> But when using HttpEntity.writeTo(OutputStream) to do something with the 
> content, what I have is the *compressed content* (e.g. length of the 
> byte array behind my ByteArrayOutputStream: 12'753), whereas 
> EntityUtils.toByteArray(HttpEntity) gives me the *uncompressed content* 
> (length=160'991), correctly processed through the 
> GzipDecompressingEntity/HttpEntityWrapper (cf 
> ClientGZipContentCompression.java).
> 
> In both cases the HttpResponseInterceptor that wraps the entity inside 
> the GzipDecompressingEntity of the example obviously does its job, it 
> just seems that HttpEntity.writeTo doesn't use the wrapper's 
> getContent() but somehow EntityUtils.toByteArray does.
> 
> Is it supposed to be that way ? I was surprised, from an API point of 
> view, that both methods did not (indirectly) yield the same result. Am I 
> missing a point somewhere ?
> 
> You can test the difference by using either one of these 2 snippets of 
> code inside ClientGZipContentCompression.java 
> (http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/httpclient/src/examples/org/apache/http/examples/client/ClientGZipContentCompression.java):

> 

This is because the GzipDecompressingEntity class in the example does 
not implement HttpEntity#writeTo() method, mainly for simplicity, and 
therefore what you get is the 'raw' content of the original entity 
without decompression.

What you need is make GzipDecompressingEntity#wtiteTo() decompress the 
content prior to writing it out to the output stream.

Hope this helps

Oleg

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


Mime
View raw message