I use some Apache Commons libraries. In particular, I'm using version 4.2.5 of httpclient
and version 2.4 of commons-io
. Thus, using a DefaultHttpClient
I try to download pdf files from URLs. E.g. Suppose that I want to download this file: http://www.lowaste.it/files/pdf/C12-02_filiere.pdf. I get a 200 response, but as one may see by using a browser, the file is never loaded. It seems that the bytes are never loaded after the first answer.
In my code, I do as follows:
HttpEntity entity =//... I get the entity via DefaultHttpClient
InputStream in = entity.getContent();
FileOutputStream out = // init the OutputStream
org.apache.commons.io.IOUtils.copy(in, out);
The function IOUtils.copy
seems to loops infinitely and never stops. I stayed ours waiting for the file to be saved.
The IOUtils.copy
function uses IOUtils.copyLarge
. I report the function for the sake of completeness:
public static long copyLarge(InputStream input, OutputStream output, byte[] buffer)
throws IOException {
long count = 0;
int n = 0;
while (EOF != (n = input.read(buffer))) {
output.write(buffer, 0, n);
count += n;
}
return count;
}
I also tried to replace IOUtils.copy(in, out)
with:
IOUtils.copy(IOUtils.toBufferedInputStream(in), out);
since object in
relies on a network connection, but it doesn't helped!
Any idea to resolve the problem?