aspose file tools*
The moose likes Java in General and the fly likes Download files with resume support Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Download files with resume support" Watch "Download files with resume support" New topic
Author

Download files with resume support

Charles Mulloy
Ranch Hand

Joined: Oct 25, 2009
Posts: 30
I'm trying to design an open source, java based download module. I'm still in the proof of concept stage though. I've made the code necessary to download a file, but to test the resume feature, I would terminate the process before the download finished and then restart it. But when it restarts, it deletes the file and makes a new one in it's place. Here is my code so far:


How can I make it pick up where it left off?

Note: Code is adapted from http://www.roseindia.net/java/java-conversion/InputstreamToFile.shtml. Not mine.
Amit Ghorpade
Bartender

Joined: Jun 06, 2007
Posts: 2716
    
    6

Go through the code above and figure out why it is deleting the file and creating a new one.

P.S If its going to be open source, then it has be your own code right?


SCJP, SCWCD.
|Asking Good Questions|
Charles Mulloy
Ranch Hand

Joined: Oct 25, 2009
Posts: 30
Found the problem.

First off, line 31 is useless. It is from a past attempt and I forgot to remove it, so ignore it altogether.

Second, the error is in line 24. I constructed the FileOutputStream wrong. I used...

This will delete the file if it exists. But this...

... will make it append to the end.

The final product (before I start adding stuff):


@Amit: I only wanted to give credit where it was due. I had code before seeing this link, but it wasn't working like I wanted. What I have now is a derivative of the code found there.
Rene Krell
Greenhorn

Joined: Apr 13, 2011
Posts: 3
Does this make sense? According to the code, this is not a clear resume, but the client skips just the portion it has already received. But in each case you re-read the file from the beginning. So if you're connection is interrupted after transferring n GB, you got the retransmit them all in each case, just the client picks the the bytes it needs from that big piece already retransferred. This doesn't save neither time nor bandwith. Am I wrong here?

IMHO, the only approach of resuming a download can be initiated by the server, by giving it the start position in the target file it should start sending at.

Rene


Charles Mulloy wrote:Found the problem.

First off, line 31 is useless. It is from a past attempt and I forgot to remove it, so ignore it altogether.

Second, the error is in line 24. I constructed the FileOutputStream wrong. I used...

This will delete the file if it exists. But this...

... will make it append to the end.

The final product (before I start adding stuff):


@Amit: I only wanted to give credit where it was due. I had code before seeing this link, but it wasn't working like I wanted. What I have now is a derivative of the code found there.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12785
    
    5
Note that HTTP has headers already defined that will let you specify the range of bytes in the resource that you want to get in the response.

Therefore your request for a resume can tell the server where to start.

Bill
Rene Krell
Greenhorn

Joined: Apr 13, 2011
Posts: 3
That's what I wanted to say in a particular example.
For practical usage, see this example: http://luugiathuy.com/2011/03/download-manager-java/ .

William Brogden wrote:Note that HTTP has headers already defined that will let you specify the range of bytes in the resource that you want to get in the response.

Therefore your request for a resume can tell the server where to start.

Bill
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Download files with resume support