cn.schoolwow.download.QuickDownload Maven / Gradle / Ivy
The newest version!
package cn.schoolwow.download;
import cn.schoolwow.download.domain.pool.DownloadPool;
import cn.schoolwow.download.domain.pool.DownloadPoolConfig;
import cn.schoolwow.download.domain.progress.DownloadProgress;
import cn.schoolwow.download.domain.task.DownloadContext;
import cn.schoolwow.download.domain.task.DownloadTask;
import cn.schoolwow.download.module.pool.DownloadPoolImpl;
import java.nio.file.Path;
import java.util.List;
import java.util.function.Consumer;
/**构建下载任务池*/
public class QuickDownload {
/**
* 默认QuickHttp客户端
*/
private static DownloadPool downloadPool = new DownloadPoolImpl();
public static DownloadPool getDefaultDownloadPool(){
return downloadPool;
}
/**
* 获取下载进度列表
* */
public static List getProgressList(){
return downloadPool.getProgressList();
}
/**
* 获取下载配置信息
* */
public static DownloadPoolConfig downloadPoolConfig(){
return downloadPool.getDownloadPoolConfig();
}
/**
* 打印下载进度表
* */
public static void printDownloadProgress(){
downloadPool.printDownloadProgress();
}
/**
* 下载单个任务
* @param downloadTask 下载任务
* */
public static DownloadContext downloadSingleTask(DownloadTask downloadTask){
downloadTask.waitFor = true;
return downloadPool.download(downloadTask)[0];
}
/**
* 下载任务
* @param downloadTasks 下载任务
* */
public static DownloadContext[] download(DownloadTask... downloadTasks){
return downloadPool.download(downloadTasks);
}
/**
* 下载任务
* @param downloadFinished 指定下载任务列表完成后执行
* @param downloadTasks 下载任务
* */
public static void download(Consumer downloadFinished, DownloadTask... downloadTasks){
downloadPool.download(downloadFinished,downloadTasks);
}
/**
* 暂停下载
* @param id 下载任务id
* */
public static void pauseDownload(long id){
downloadPool.pauseDownload(id);
}
/**
* 恢复下载
* @param id 下载任务id
* */
public static void resumeDownload(long id){
downloadPool.resumeDownload(id);
}
/**
* 新建下载池
*/
public static DownloadPool newDownloadPool() {
return new DownloadPoolImpl();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy