Java中的下载管理器 [英] Download manager in Java

查看:300
本文介绍了Java中的下载管理器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从Java通过FTP / HTTP几个巨大的文件(几个gig)。有没有一个可用的库(java /命令行工具)来方便下载?一些明显的要求是:


  1. 多连接下载 - 应该可以打开多个连接到服务器来加速下载(如FlashGet / GetRight /...)

  2. 恢复下载

修改 - 我真的不想写这样一个图书馆,但是窃取(或支付)一个现有的测试,生产级别的图书馆。 rsynch不相关,因为我需要从HTTP和FTP站点下载文件,不是内部文件传输。

解决方案

如果你知道如何在java中创建套接字和线程并不困难。



首先创建请求并读取头文件以获取 Content-length 头。然后设计出一个策略来分割你的请求,例如大约500K的请求。然后开始说每个请求使用一个线程10个请求。在每个请求中,您必须定义 Range 头。



恢复您的下载是存储您尚未下载的范围的问题。
我建议你阅读这个HTTP / 1.1标题字段RFC here 如果你真的想要很好地掌握所使用的协议。



但是,如果你正在寻找一个简单的方法,rsync或scp应该足够了。 p>

I need to several some huge files (several gigs) from Java via FTP/HTTP. Is there a ready library (java / command line tool) to facilitate the download? Some obvious requirements are:

  1. Multi-connection download - should be able to open several connections to the server to accelerate the download (like FlashGet/GetRight/...)
  2. Resume a download

Edit - I'd really prefer not to write such a library but steal it (or pay) for an existing tested, production grade library. rsynch is not relevant since I need to download files from HTTP and FTP sites, it's not for internal file transfer.

解决方案

If you know how to create sockets and threads in java it's not that difficult.

First create a request and read the headers to get the Content-length header. Then devise a strategy to split your request in chunks of for example 500K each request. Then start say 10 requests using a thread for each request. In each request you have to define the Range header.

Resuming your download is a matter of storing the ranges you haven't downloaded yet. I suggest you read this HTTP/1.1 Header Fields RFC here if you really want to get a good grasp on the protocol used.

However if you're looking for an easy way out rsync or scp should suffice.

这篇关于Java中的下载管理器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆