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 Bogdan Mihaila <bm...@yahoo.com> on 2006/01/24 11:56:49 UTC
response body as stream
Hello!
I try to download ZIP files with httpclient, and I want to get the response as stream, not as byte[]... It downloades the files (the sizes are Ok), but when I open the archives It gives me: "error in packed file" and "invalid bit length repeat".
I use the following code:
Reader reader = new InputStreamReader(
method.getResponseBodyAsStream(), method.getResponseCharSet());
// I use the Commons IO package
BufferedWriter out = new BufferedWriter(new FileWriter("...."));
out.write(IOUtils.toString(reader));
out.close();
What can be the problem?
Thanks in advance
---------------------------------
Yahoo! Autos. Looking for a sweet ride? Get pricing, reviews, & more on new and used cars.
Re: response body as stream
Posted by Jeroen ter Voorde <j....@home.nl>.
Hi,
You should use a FileOutputStream and directly stream the response body
stream instead of using a Reader and Writer (which performs
character decoding using the supplied charset and therefore corrupts
your file).
Jeroen
Bogdan Mihaila wrote:
>Hello!
>
> I try to download ZIP files with httpclient, and I want to get the response as stream, not as byte[]... It downloades the files (the sizes are Ok), but when I open the archives It gives me: "error in packed file" and "invalid bit length repeat".
>
> I use the following code:
>
> Reader reader = new InputStreamReader(
> method.getResponseBodyAsStream(), method.getResponseCharSet());
>
> // I use the Commons IO package
>
> BufferedWriter out = new BufferedWriter(new FileWriter("...."));
> out.write(IOUtils.toString(reader));
> out.close();
>
> What can be the problem?
>
> Thanks in advance
>
>
>
>---------------------------------
> Yahoo! Autos. Looking for a sweet ride? Get pricing, reviews, & more on new and used cars.
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org