package com.persist.download;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import java.io.*;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
/**
*多线程文件下载器
*下载线程数 默认为4
* 建议不要配置过多,可以考虑CPU*2
* */publicclassDownload {
privatefinalstaticint DEFAULT_THREAD_NUM = 4;
//the uri of the file to be downloadedprivate String uri;
//the path to save the local fileprivate String savePath;
//the true num of thread to execute download taskprivateint threadNum;
//the file sizeprivatelong fileSize;
//the size of each part to be downloadedprivatelong partSize;
//the download thread arrayprivate DownloadThread[] downloadThread;
//the num of the thread which is really startedprivateint realThreadNum;
//the num of the finished threadprivateint overThreadNum;
//the tail of the tmp file which records the download info of each part//the download info will be store with json.// when download is finished,the tmp file will be deleted.privatefinalstatic String tmpTail = "-tmp";
//the download info of each partprivate List<DownloadInfo> downloadInfos;
publicDownload(String uri, String savePath, int threadNum) {
this.uri = uri;
this.savePath = savePath;
this.threadNum = threadNum;
downloadThread = new DownloadThread[threadNum];
}
publicDownload(String uri, String savePath) {
//default thread num is 4t