views:

217

answers:

2

Hi, We have a requirement to download multiple documents, zip them and allow user to download zip file. The documents are downloaded sequentially and the number of documents can be upto 30 documents with varied sizes. We are planning to use URLConnection or any other open source urlconnection API if they have better features.

What we would like to understand is there could be files which are large in size (may be 40-50 MB) and could take more time to download such files. We would like to have the logic to determine the size, avoid downloading such files which are either large in size or for which its taking considerable amount of time to download.

Appreciate any thoughs on the best way to avoid file downloading either based on time or the size of document.

Thanks.

A: 

as you are downloading from a web server there is no guaranteed way of knowing the size of the file in advance. content-length in the header may or may not be accurate or even sent.

Sabeen Malik
A: 

Thanks for the answers. Is there a way I can disconnect URLConnection if it takes beyond a pre defined time say for example beyond 5 minutes (even though its still downloading), we may want to disconnect it between if its taking considerable amount of time.

stranger001
i havent got much experience with java but from what i know URLConnection doesn't allow timeouts. It would go in blocking mode so even putting that in a thread wont work as the interrupt call wont be reached until its done. You can look into HTTPClient which provides timeout capability.
Sabeen Malik

related questions