Question

I'm trying to use the jakarta commons HttpClient library.

I think I'm being dumb here, but I can't figure out how to write a complete HttpEntity to file.

I'm trying:

FileOutputStream os = new FileOutputStream(f);

e.writeTo(os);
while (e.isStreaming()) {
   e.writeTo(os);
}

Where e is my HttpEntity and f is my file. I only get the first 8KB of any file, I guess due to buffering somewhere. Any idea how I get the rest?

Was it helpful?

Solution

Solved it.

I needed to force the response object to use a BufferedHttpEntity:

HttpEntity entity = rsp.getEntity();
BufferedHttpEntity buf = new BufferedHttpEntity(entity);

OTHER TIPS

response = httpclient.execute(get);
is = response.getEntity().getContent();
IOUtils.copy(is,fileWriter);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top