public class HttpDownloader extends Object
HttpDownloader.of(url).downloadFile(file)
2. 多次下载复用:
HttpDownloader downloader = HttpDownloader.of(url).setCloseEngine(false);
downloader.downloadFile(file);
downloader.downloadFile(file2);
downloader.close();
Constructor and Description |
---|
HttpDownloader(String url)
构造
|
Modifier and Type | Method and Description |
---|---|
long |
download(OutputStream out,
boolean isCloseOut)
下载文件
|
File |
downloadFile(File targetFileOrDir)
下载文件
|
File |
downloadFile(File targetFileOrDir,
String tempFileSuffix)
下载文件
|
HttpDownloader |
header(Map<String,String> headers)
设置请求头
|
HttpDownloader |
header(String name,
String value)
设置请求头,多个请求头则多次调用
|
static HttpDownloader |
of(String url)
创建下载器
|
HttpDownloader |
setCloseEngine(boolean closeEngine)
设置是否关闭引擎,默认为true,即自动关闭引擎
|
HttpDownloader |
setConfig(ClientConfig config)
设置配置
|
HttpDownloader |
setEngine(ClientEngine engine)
设置引擎,用于自定义引擎
|
HttpDownloader |
setStreamProgress(StreamProgress streamProgress)
设置进度条
|
HttpDownloader |
setTimeout(int milliseconds)
设置超时
|
public HttpDownloader(String url)
url
- 请求地址public static HttpDownloader of(String url)
url
- 请求地址public HttpDownloader header(Map<String,String> headers)
headers
- 请求头public HttpDownloader header(String name, String value)
name
- 请求头名value
- 请求头值public HttpDownloader setConfig(ClientConfig config)
config
- 配置public HttpDownloader setTimeout(int milliseconds)
milliseconds
- 超时毫秒数public HttpDownloader setEngine(ClientEngine engine)
engine
- 引擎public HttpDownloader setStreamProgress(StreamProgress streamProgress)
streamProgress
- 进度条public HttpDownloader setCloseEngine(boolean closeEngine)
closeEngine
- 是否关闭引擎public File downloadFile(File targetFileOrDir)
targetFileOrDir
- 目标文件或目录,当为目录时,自动使用文件名作为下载文件名public File downloadFile(File targetFileOrDir, String tempFileSuffix)
targetFileOrDir
- 目标文件或目录,当为目录时,自动使用文件名作为下载文件名tempFileSuffix
- 临时文件后缀public long download(OutputStream out, boolean isCloseOut)
out
- 输出流isCloseOut
- 是否关闭输出流,true关闭Copyright © 2025. All rights reserved.