• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Download files with resume support

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Bartender
Posts: 2856
10
Firefox Browser Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Charles Mulloy
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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

 
Be reasonable. You can't destroy everything. Where would you sit? How would you read a tiny ad?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic