Java 中的下载管理器

发布于 2024-08-10 01:02:25 字数 1539 浏览 4 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

不爱素颜 2024-08-17 01:02:25

HTTP 协议确实支持以偏移量开始部分下载,但对验证文件的本地部分版本以确保其末尾没有附加垃圾(或类似内容)的支持有限。如果您的环境允许,我建议使用 --partial 选项进行 rsync。它旨在从命令行支持此类功能。

如果您无法使用 rsync,您可能需要尝试使用 Commons-HTTPClient 并利用 Range HTTP 标头来下载可管理大小的块。

The HTTP protocol does support starting a partial download at an offset, but has limited support for validating the local partial version of the file to make sure that it doesn't have junk attached to the end (or something similar). If your environment allows it, I recommend rsync with the --partial option. Its designed to support this kind of functionality from the command line.

If you can't use rsync, you may want to try working with Commons-HTTPClient and utilizing the Range HTTP header to download manageable sized chunks.

冰雪梦之恋 2024-08-17 01:02:25

如果您知道如何在 java 中创建套接字和线程,那么这并不困难。

首先创建一个请求并读取标头以获取 Content-length 标头。然后设计一个策略将您的请求分成多个块,例如每个请求 500K。然后开始假设 10 个请求,每个请求使用一个线程。在每个请求中,您必须定义 Range 标头。

恢复下载就是存储尚未下载的范围。
我建议您在此处阅读此 HTTP/1.1 标头字段 RFC真的想很好地掌握所使用的协议。

但是,如果您正在寻找一种简单的方法,rsync 或 scp 就足够了。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文