开发者

Download Manager Network Failure Issue

开发者 https://www.devze.com 2023-03-26 21:12 出处:网络
I am making a download utility in java开发者_开发问答 which will download files from the ftp server.

I am making a download utility in java开发者_开发问答 which will download files from the ftp server. I am using URLConnection class to establish connection and inputstream as the stream object. The problem that i am facing is in the network failure scenario i.e while downloading a particular file if the connectivity is lost and after the connectivity is restored i want it to resume downloading from where it had stopped previously.

To achieve this i have done the foll :-

/*Here,I am trying to skip the number of bytes downloaded so far so as to get the pointer in stream from where it should resume downloading.The skip() method may not necessarily skip the number of bytes given as a parameter and hence the while loop. */

while(totalByteSkipped!=downloaded) 
{ 
      bytesSkipped = stream.skip(downloaded-totalByteSkipped); 

      totalByteSkipped = totalByteSkipped+bytesSkipped; 
} 

But this approach of manually skipping so many bytes is very slow and affects the overall time of download, hence in such a case i need a mechanism to get the pointer in the stream at the point where it had stopped downloading.

Hoping to get an alternative approach on the same. Thanks!!


You need to implement FPT restart in order to resume downloads. If your server supports it, then you can tell it the offset in the file.

Is there any reason why you are not using an already existent FTP Client? Commons Net FTP Client supports restart.


skip() wont work for you because it just downloads all the data and then discards it. The server is not informed that these bits are discarded, they are discarded at the client.

You are looking at the wrong end. Check if the FTP protocol (or whatever you use) allows for this behavior and which instructions you must send to use it. Otherwise they will just keep in sending you all of the data from the beginning, even if you do not want it.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号