File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes downloading a huge file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "downloading a huge file" Watch "downloading a huge file" New topic
Author

downloading a huge file

pendse anagha
Ranch Hand

Joined: Mar 09, 2005
Posts: 44
Hello ,
I have a search screen - where user enters a number of parameters and based on these inputs - system searches the database tables and gets the results

System then generates a csv file and this is returned to the user

The entrie activity is synchronous .

The problem is - in the tables there are practically millions of records
so application just sits till results are returned

This could take loads of time - which is not desirable

Can someone suggest a asynchronous approach

I was thinking of this approach - where asynchronously some kind of scheduler processes the data and then sends across a link via email

However - the problem is - the user will then have to again authenticate
himself

I do not want the user to again authenticate

( I am not using cokkies for authentication - using HttpSession )

Your suggestions are most welcome

Thanks in advance.
-anagha
Robert Watkins
Greenhorn

Joined: Sep 20, 2005
Posts: 25
Easiest way I can think of, if all you care about is giving the user some feedback, is to do the download in a seperate thread.

Once the downloading is in a seperate thread, you can attach a progress bar of some sort to it. Read the contents of the file in some not-too-large chunks (say, 10KB at a time) - on receiving each chunk, update the progress bar, and write the chunk to the destination file.

If you can find out in advance how large the file you're going to download is (even approximately) you can use this information to tailor the progress bar.

Note that you can also give the progress bar a cancel option - this would simply tell the downloading thread to abort.

Last, but no least - if the progress bar is not a modal window, the user can continue to work in the application while the download occurs.

Okay, all that assumed you were in a GUI application... if you're in a web based application, you can still do the progress bar, and the seperate thread work - simply place the spawned thread inside the user's session. However, if the file is truly big, you'll want to do it all synchronously anyway - the last thing you want is to have your server holding large files in memory all the time.

Finally - if avoiding authentication is all you care about, send the user an email with a one-off random token - say, about 200 characters long. This could then be used to retrieve the file without authentication with a some degree of security (based on obscurity). Naturally, you'd want the tokens to only be valid for a limited period of time.


Software is too expensive to build cheaply...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: downloading a huge file