优化代码,删除一些无用的api
Change-Id: If9c79ebd7ddec2cb0f01539f4d38555608e14bea
This commit is contained in:
@@ -36,12 +36,13 @@ import java.util.concurrent.Executors;
|
||||
|
||||
/**
|
||||
* Created by AriaL on 2017/7/1.
|
||||
* 文件下载器
|
||||
* 任务处理器
|
||||
*/
|
||||
public abstract class AbsFileer<ENTITY extends AbsNormalEntity, TASK_ENTITY extends AbsTaskEntity<ENTITY>>
|
||||
implements Runnable, IUtil {
|
||||
public static final String STATE = "_state_";
|
||||
public static final String RECORD = "_record_";
|
||||
protected static final long SUB_LEN = 1024 * 1024;
|
||||
|
||||
private final String TAG = "AbsFileer";
|
||||
protected IEventListener mListener;
|
||||
@@ -49,7 +50,7 @@ public abstract class AbsFileer<ENTITY extends AbsNormalEntity, TASK_ENTITY exte
|
||||
protected ENTITY mEntity;
|
||||
protected File mConfigFile;//信息配置文件
|
||||
protected Context mContext;
|
||||
protected File mTempFile; //下载的文件
|
||||
protected File mTempFile; //文件
|
||||
protected boolean isNewTask = true;
|
||||
protected StateConstance mConstance;
|
||||
private ExecutorService mFixedThreadPool;
|
||||
@@ -64,7 +65,6 @@ public abstract class AbsFileer<ENTITY extends AbsNormalEntity, TASK_ENTITY exte
|
||||
/**
|
||||
* 小于1m的文件不启用多线程
|
||||
*/
|
||||
private static final long SUB_LEN = 1024 * 1024;
|
||||
private Timer mTimer;
|
||||
private long mUpdateInterval = 1000;
|
||||
|
||||
@@ -89,9 +89,6 @@ public abstract class AbsFileer<ENTITY extends AbsNormalEntity, TASK_ENTITY exte
|
||||
}
|
||||
}
|
||||
|
||||
public StateConstance getConstance() {
|
||||
return mConstance;
|
||||
}
|
||||
|
||||
@Override public void run() {
|
||||
if (mConstance.isRunning) {
|
||||
@@ -101,7 +98,7 @@ public abstract class AbsFileer<ENTITY extends AbsNormalEntity, TASK_ENTITY exte
|
||||
}
|
||||
|
||||
/**
|
||||
* 开始下载流程
|
||||
* 开始流程
|
||||
*/
|
||||
private void startFlow() {
|
||||
mConstance.resetState();
|
||||
@@ -115,7 +112,7 @@ public abstract class AbsFileer<ENTITY extends AbsNormalEntity, TASK_ENTITY exte
|
||||
mConstance.THREAD_NUM = mTotalThreadNum;
|
||||
handleNoSupportBP();
|
||||
} else {
|
||||
mTotalThreadNum = isNewTask ? (getNewTaskThreadNum()) : mStartThreadNum;
|
||||
mTotalThreadNum = isNewTask ? (mStartThreadNum = setNewTaskThreadNum()) : mStartThreadNum;
|
||||
mConstance.THREAD_NUM = mTotalThreadNum;
|
||||
handleBreakpoint();
|
||||
}
|
||||
@@ -125,13 +122,7 @@ public abstract class AbsFileer<ENTITY extends AbsNormalEntity, TASK_ENTITY exte
|
||||
/**
|
||||
* 设置新任务的最大线程数
|
||||
*/
|
||||
protected int getNewTaskThreadNum() {
|
||||
final int num =
|
||||
mEntity.getFileSize() <= SUB_LEN || mTaskEntity.requestType == AbsTaskEntity.D_FTP_DIR ? 1
|
||||
: AriaManager.getInstance(mContext).getDownloadConfig().getThreadNum();
|
||||
mStartThreadNum = num;
|
||||
return num;
|
||||
}
|
||||
protected abstract int setNewTaskThreadNum();
|
||||
|
||||
/**
|
||||
* 启动进度获取定时器
|
||||
@@ -165,13 +156,12 @@ public abstract class AbsFileer<ENTITY extends AbsNormalEntity, TASK_ENTITY exte
|
||||
*
|
||||
* @param interval 单位毫秒,不能小于0
|
||||
*/
|
||||
protected long setUpdateInterval(long interval) {
|
||||
protected void setUpdateInterval(long interval) {
|
||||
if (interval < 0) {
|
||||
ALog.w(TAG, "更新间隔不能小于0,默认为1000毫秒");
|
||||
return 1000;
|
||||
return;
|
||||
}
|
||||
mUpdateInterval = interval;
|
||||
return interval;
|
||||
}
|
||||
|
||||
@Override public long getFileSize() {
|
||||
@@ -236,12 +226,6 @@ public abstract class AbsFileer<ENTITY extends AbsNormalEntity, TASK_ENTITY exte
|
||||
start();
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回该下载器的
|
||||
*/
|
||||
public IEventListener getListener() {
|
||||
return mListener;
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查任务是否是新任务,新任务条件:
|
||||
@@ -296,7 +280,7 @@ public abstract class AbsFileer<ENTITY extends AbsNormalEntity, TASK_ENTITY exte
|
||||
/**
|
||||
* 恢复记录地址
|
||||
*
|
||||
* @return true 表示下载完成
|
||||
* @return {@code true}任务已完成
|
||||
*/
|
||||
private boolean resumeRecordLocation(int i, long startL, long endL) {
|
||||
mConstance.CURRENT_LOCATION += endL - startL;
|
||||
|
||||
@@ -18,7 +18,7 @@ package com.arialyy.aria.core.common;
|
||||
|
||||
/**
|
||||
* Created by lyy on 2016/10/31.
|
||||
* 抽象的下载接口
|
||||
* 任务功能接口
|
||||
*/
|
||||
public interface IUtil {
|
||||
|
||||
@@ -28,39 +28,39 @@ public interface IUtil {
|
||||
long getFileSize();
|
||||
|
||||
/**
|
||||
* 获取当前下载位置
|
||||
* 获取当前位置
|
||||
*/
|
||||
long getCurrentLocation();
|
||||
|
||||
/**
|
||||
* 是否正在下载
|
||||
* 任务是否正在执行
|
||||
*
|
||||
* @return true, 正在下载
|
||||
* @return {@code true} 任务正在执行
|
||||
*/
|
||||
boolean isRunning();
|
||||
|
||||
/**
|
||||
* 取消下载
|
||||
* 取消
|
||||
*/
|
||||
void cancel();
|
||||
|
||||
/**
|
||||
* 停止下载
|
||||
* 停止
|
||||
*/
|
||||
void stop();
|
||||
|
||||
/**
|
||||
* 开始下载
|
||||
* 开始
|
||||
*/
|
||||
void start();
|
||||
|
||||
/**
|
||||
* 从上次断点恢复下载
|
||||
* 从上次断点恢复
|
||||
*/
|
||||
void resume();
|
||||
|
||||
/**
|
||||
* 设置最大下载速度
|
||||
* 设置最大速度
|
||||
*/
|
||||
void setMaxSpeed(double maxSpeed);
|
||||
}
|
||||
@@ -18,7 +18,6 @@ package com.arialyy.aria.core.delegate;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.text.TextUtils;
|
||||
import com.arialyy.aria.core.common.RequestEnum;
|
||||
import com.arialyy.aria.core.download.DownloadEntity;
|
||||
import com.arialyy.aria.core.inf.AbsEntity;
|
||||
import com.arialyy.aria.core.inf.AbsTaskEntity;
|
||||
import com.arialyy.aria.core.inf.IHttpHeaderTarget;
|
||||
@@ -140,66 +139,4 @@ public class HttpHeaderDelegate<TARGET extends ITarget, ENTITY extends AbsEntity
|
||||
mTaskEntity.requestEnum = requestEnum;
|
||||
return mTarget;
|
||||
}
|
||||
|
||||
/**
|
||||
* 如果你的下载链接的header中含有md5码信息,那么你可以通过设置key,来获取从header获取该md5码信息。
|
||||
* key默认值为:Content-MD5
|
||||
* 获取md5信息:{@link DownloadEntity#getMd5Code()}
|
||||
*/
|
||||
@Override
|
||||
public TARGET setHeaderMd5Key(String md5Key) {
|
||||
if (TextUtils.isEmpty(md5Key)) return mTarget;
|
||||
mTaskEntity.md5Key = md5Key;
|
||||
if (TextUtils.isEmpty(mTaskEntity.md5Key) || !mTaskEntity.md5Key.equals(md5Key)) {
|
||||
mTaskEntity.update();
|
||||
}
|
||||
return mTarget;
|
||||
}
|
||||
|
||||
/**
|
||||
* 如果你的文件长度是放在header中,那么你需要配置key来让Aria知道正确的文件长度
|
||||
* key默认值为:Content-Length
|
||||
*/
|
||||
@Override
|
||||
public TARGET setHeaderContentLengthKey(String contentLength) {
|
||||
if (TextUtils.isEmpty(contentLength)) return mTarget;
|
||||
mTaskEntity.contentLength = contentLength;
|
||||
if (TextUtils.isEmpty(mTaskEntity.contentLength) || !mTaskEntity.contentLength.equals(
|
||||
contentLength)) {
|
||||
mTaskEntity.update();
|
||||
}
|
||||
return mTarget;
|
||||
}
|
||||
|
||||
/**
|
||||
* 如果你的下载链接的header中含有文件描述信息,那么你可以通过设置key,来获取从header获取该文件描述信息。
|
||||
* key默认值为:Content-Disposition
|
||||
* 获取文件描述信息:{@link DownloadEntity#getDisposition()}
|
||||
*/
|
||||
@Override
|
||||
public TARGET setHeaderDispositionKey(String dispositionKey) {
|
||||
if (TextUtils.isEmpty(dispositionKey)) return mTarget;
|
||||
mTaskEntity.dispositionKey = dispositionKey;
|
||||
if (TextUtils.isEmpty(mTaskEntity.dispositionKey) || !mTaskEntity.dispositionKey.equals(
|
||||
dispositionKey)) {
|
||||
mTaskEntity.update();
|
||||
}
|
||||
return mTarget;
|
||||
}
|
||||
|
||||
/**
|
||||
* 从文件描述信息{@link #setHeaderDispositionKey(String)}中含有文件名信息,你可以通过设置key来获取header中的文件名
|
||||
* key默认值为:attachment;filename
|
||||
* 获取文件名信息:{@link DownloadEntity#getServerFileName()}
|
||||
*/
|
||||
@Override
|
||||
public TARGET setHeaderDispositionFileKey(String dispositionFileKey) {
|
||||
if (TextUtils.isEmpty(dispositionFileKey)) return mTarget;
|
||||
mTaskEntity.dispositionFileKey = dispositionFileKey;
|
||||
if (TextUtils.isEmpty(mTaskEntity.dispositionFileKey) || !mTaskEntity.dispositionFileKey.equals(
|
||||
dispositionFileKey)) {
|
||||
mTaskEntity.update();
|
||||
}
|
||||
return mTarget;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,35 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.arialyy.aria.core.delegate;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Created by AriaL on 2018/3/17.
|
||||
* 参数容器,用来临时存储链式命令的需要的参数。
|
||||
*/
|
||||
public class ParamContainer {
|
||||
|
||||
public String url;
|
||||
public String filePath;
|
||||
public String charSet;
|
||||
public Map<String, String> header = new HashMap<>();
|
||||
|
||||
// ftp 相关的
|
||||
public String userName, userPw, userAccount;
|
||||
public boolean needLogin;
|
||||
}
|
||||
@@ -15,13 +15,11 @@
|
||||
*/
|
||||
package com.arialyy.aria.core.download;
|
||||
|
||||
import android.text.TextUtils;
|
||||
import com.arialyy.aria.core.AriaManager;
|
||||
import com.arialyy.aria.core.command.normal.NormalCmdFactory;
|
||||
import com.arialyy.aria.core.inf.AbsEntity;
|
||||
import com.arialyy.aria.core.inf.AbsTarget;
|
||||
import com.arialyy.aria.core.inf.AbsTaskEntity;
|
||||
import com.arialyy.aria.util.ALog;
|
||||
import com.arialyy.aria.util.CommonUtil;
|
||||
|
||||
/**
|
||||
@@ -72,17 +70,6 @@ abstract class AbsDownloadTarget<TARGET extends AbsTarget, ENTITY extends AbsEnt
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 重定向后,新url的key,默认为location
|
||||
*/
|
||||
public void setRedirectUrlKey(String redirectUrlKey) {
|
||||
if (TextUtils.isEmpty(redirectUrlKey)) {
|
||||
ALog.e("AbsDownloadTarget", "重定向后,新url的key不能为null");
|
||||
return;
|
||||
}
|
||||
mTaskEntity.redirectUrlKey = redirectUrlKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取任务文件大小
|
||||
*
|
||||
|
||||
@@ -35,23 +35,6 @@ abstract class BaseNormalTarget<TARGET extends BaseNormalTarget>
|
||||
*/
|
||||
protected String url;
|
||||
|
||||
/**
|
||||
* 通过实体初始化target
|
||||
*/
|
||||
void initTarget(DownloadEntity entity, String targetName, boolean refreshInfo) {
|
||||
this.url = entity.getUrl();
|
||||
mTargetName = targetName;
|
||||
mTaskEntity = TEManager.getInstance().getTEntity(DownloadTaskEntity.class, url);
|
||||
if (mTaskEntity == null) {
|
||||
mTaskEntity = TEManager.getInstance().createTEntity(DownloadTaskEntity.class, entity);
|
||||
}
|
||||
mEntity = mTaskEntity.entity;
|
||||
mTaskEntity.refreshInfo = refreshInfo;
|
||||
if (mEntity != null) {
|
||||
mTempFilePath = mEntity.getDownloadPath();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过地址初始化target
|
||||
*/
|
||||
|
||||
@@ -43,13 +43,13 @@ public class DownloadEntity extends AbsNormalEntity implements Parcelable {
|
||||
@Foreign(table = DownloadTaskEntity.class, column = "key") private String taskKey = "";
|
||||
|
||||
/**
|
||||
* 通过{@link AbsTaskEntity#md5Key}从服务器的返回信息中获取的文件md5信息,如果服务器没有返回,则不会设置该信息
|
||||
* 从服务器的返回信息中获取的文件md5信息,如果服务器没有返回,则不会设置该信息
|
||||
* 如果你已经设置了该任务的MD5信息,Aria也不会从服务器返回的信息中获取该信息
|
||||
*/
|
||||
private String md5Code = "";
|
||||
|
||||
/**
|
||||
* 通过{@link AbsTaskEntity#dispositionKey}从服务器的返回信息中获取的文件描述信息
|
||||
* 从服务器的返回信息中获取的文件描述信息
|
||||
*/
|
||||
private String disposition = "";
|
||||
|
||||
@@ -117,8 +117,6 @@ public class DownloadEntity extends AbsNormalEntity implements Parcelable {
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override public DownloadEntity clone() throws CloneNotSupportedException {
|
||||
return (DownloadEntity) super.clone();
|
||||
}
|
||||
|
||||
@@ -182,7 +182,7 @@ public class DownloadReceiver extends AbsReceiver {
|
||||
*
|
||||
* @param groupEntity 如果加载的任务实体没有子项的下载地址,
|
||||
* 那么你需要使用{@link DownloadGroupTarget#setGroupUrl(List)}设置子项的下载地址
|
||||
* @deprecated {@link #loadGroup(DownloadGroupEntity)}
|
||||
* @deprecated 请使用 {@link #loadGroup(DownloadGroupEntity)}
|
||||
*/
|
||||
@Deprecated
|
||||
public DownloadGroupTarget load(DownloadGroupEntity groupEntity) {
|
||||
|
||||
@@ -35,8 +35,7 @@ public class DownloadTarget extends BaseNormalTarget<DownloadTarget>
|
||||
}
|
||||
|
||||
DownloadTarget(DownloadEntity entity, String targetName, boolean refreshInfo) {
|
||||
initTarget(entity, targetName, refreshInfo);
|
||||
initTHis();
|
||||
this(entity.getUrl(), targetName, refreshInfo);
|
||||
}
|
||||
|
||||
DownloadTarget(String url, String targetName) {
|
||||
@@ -45,10 +44,6 @@ public class DownloadTarget extends BaseNormalTarget<DownloadTarget>
|
||||
|
||||
DownloadTarget(String url, String targetName, boolean refreshInfo) {
|
||||
initTarget(url, targetName, refreshInfo);
|
||||
initTHis();
|
||||
}
|
||||
|
||||
private void initTHis() {
|
||||
mDelegate = new HttpHeaderDelegate<>(this, mTaskEntity);
|
||||
}
|
||||
|
||||
@@ -110,20 +105,4 @@ public class DownloadTarget extends BaseNormalTarget<DownloadTarget>
|
||||
@Override public DownloadTarget setRequestMode(RequestEnum requestEnum) {
|
||||
return mDelegate.setRequestMode(requestEnum);
|
||||
}
|
||||
|
||||
@Override public DownloadTarget setHeaderMd5Key(String md5Key) {
|
||||
return mDelegate.setHeaderMd5Key(md5Key);
|
||||
}
|
||||
|
||||
@Override public DownloadTarget setHeaderContentLengthKey(String contentLength) {
|
||||
return mDelegate.setHeaderContentLengthKey(contentLength);
|
||||
}
|
||||
|
||||
@Override public DownloadTarget setHeaderDispositionKey(String dispositionKey) {
|
||||
return mDelegate.setHeaderDispositionKey(dispositionKey);
|
||||
}
|
||||
|
||||
@Override public DownloadTarget setHeaderDispositionFileKey(String dispositionFileKey) {
|
||||
return mDelegate.setHeaderDispositionFileKey(dispositionFileKey);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@ package com.arialyy.aria.core.download;
|
||||
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.util.Log;
|
||||
import com.arialyy.aria.core.AriaManager;
|
||||
import com.arialyy.aria.core.common.IUtil;
|
||||
import com.arialyy.aria.core.download.downloader.SimpleDownloadUtil;
|
||||
@@ -78,16 +77,11 @@ public class DownloadTask extends AbsNormalTask<DownloadTaskEntity> {
|
||||
}
|
||||
|
||||
/**
|
||||
* 任务下载状态
|
||||
*
|
||||
* @see DownloadTask#isRunning()
|
||||
* 是否真正下载
|
||||
* @return {@code true} 真正下载
|
||||
*/
|
||||
@Deprecated public boolean isDownloading() {
|
||||
return mUtil.isRunning();
|
||||
}
|
||||
|
||||
@Override public boolean isRunning() {
|
||||
return isDownloading();
|
||||
return mUtil.isRunning();
|
||||
}
|
||||
|
||||
public DownloadEntity getDownloadEntity() {
|
||||
|
||||
@@ -31,8 +31,7 @@ public class FtpDownloadTarget extends BaseNormalTarget<FtpDownloadTarget>
|
||||
private FtpDelegate<FtpDownloadTarget, DownloadEntity, DownloadTaskEntity> mDelegate;
|
||||
|
||||
FtpDownloadTarget(DownloadEntity entity, String targetName, boolean refreshInfo) {
|
||||
initTarget(entity, targetName, refreshInfo);
|
||||
init(refreshInfo);
|
||||
this(entity.getUrl(), targetName, refreshInfo);
|
||||
}
|
||||
|
||||
FtpDownloadTarget(String url, String targetName) {
|
||||
|
||||
@@ -389,7 +389,7 @@ public abstract class AbsGroupUtil implements IUtil {
|
||||
*
|
||||
* @param start 是否启动下载
|
||||
*/
|
||||
Downloader createChildDownload(DownloadTaskEntity taskEntity, boolean start) {
|
||||
private Downloader createChildDownload(DownloadTaskEntity taskEntity, boolean start) {
|
||||
ChildDownloadListener listener = new ChildDownloadListener(taskEntity);
|
||||
Downloader dt = new Downloader(listener, taskEntity);
|
||||
mDownloaderMap.put(taskEntity.getEntity().getUrl(), dt);
|
||||
@@ -417,7 +417,6 @@ public abstract class AbsGroupUtil implements IUtil {
|
||||
taskEntity.entity = entity;
|
||||
taskEntity.headers = mGTEntity.headers;
|
||||
taskEntity.requestEnum = mGTEntity.requestEnum;
|
||||
taskEntity.redirectUrlKey = mGTEntity.redirectUrlKey;
|
||||
taskEntity.removeFile = mGTEntity.removeFile;
|
||||
taskEntity.groupName = mGTEntity.key;
|
||||
taskEntity.isGroupTask = true;
|
||||
|
||||
@@ -81,28 +81,28 @@ class ConnectionHelp {
|
||||
conn.setRequestProperty("User-Agent",
|
||||
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36");
|
||||
}
|
||||
//if (keys == null || !keys.contains("Accept")) {
|
||||
// StringBuilder accept = new StringBuilder();
|
||||
// accept.append("image/gif, ")
|
||||
// .append("image/jpeg, ")
|
||||
// .append("image/pjpeg, ")
|
||||
// .append("image/webp, ")
|
||||
// .append("image/apng, ")
|
||||
// .append("application/xml, ")
|
||||
// .append("application/xaml+xml, ")
|
||||
// .append("application/xhtml+xml, ")
|
||||
// .append("application/x-shockwave-flash, ")
|
||||
// .append("application/x-ms-xbap, ")
|
||||
// .append("application/x-ms-application, ")
|
||||
// .append("application/msword, ")
|
||||
// .append("application/vnd.ms-excel, ")
|
||||
// .append("application/vnd.ms-xpsdocument, ")
|
||||
// .append("application/vnd.ms-powerpoint, ")
|
||||
// .append("text/plain, ")
|
||||
// .append("text/html, ")
|
||||
// .append("*/*");
|
||||
// conn.setRequestProperty("Accept", accept.toString());
|
||||
//}
|
||||
if (keys == null || !keys.contains("Accept")) {
|
||||
StringBuilder accept = new StringBuilder();
|
||||
accept.append("image/gif, ")
|
||||
.append("image/jpeg, ")
|
||||
.append("image/pjpeg, ")
|
||||
.append("image/webp, ")
|
||||
.append("image/apng, ")
|
||||
.append("application/xml, ")
|
||||
.append("application/xaml+xml, ")
|
||||
.append("application/xhtml+xml, ")
|
||||
.append("application/x-shockwave-flash, ")
|
||||
.append("application/x-ms-xbap, ")
|
||||
.append("application/x-ms-application, ")
|
||||
.append("application/msword, ")
|
||||
.append("application/vnd.ms-excel, ")
|
||||
.append("application/vnd.ms-xpsdocument, ")
|
||||
.append("application/vnd.ms-powerpoint, ")
|
||||
.append("text/plain, ")
|
||||
.append("text/html, ")
|
||||
.append("*/*");
|
||||
conn.setRequestProperty("Accept", accept.toString());
|
||||
}
|
||||
if (keys == null || !keys.contains("Accept-Encoding")) {
|
||||
conn.setRequestProperty("Accept-Encoding", "identity");
|
||||
}
|
||||
|
||||
@@ -44,6 +44,12 @@ class Downloader extends AbsFileer<DownloadEntity, DownloadTaskEntity> {
|
||||
AriaManager.getInstance(AriaManager.APP).getDownloadConfig().getUpdateInterval());
|
||||
}
|
||||
|
||||
@Override protected int setNewTaskThreadNum() {
|
||||
return mEntity.getFileSize() <= SUB_LEN || mTaskEntity.requestType == AbsTaskEntity.D_FTP_DIR
|
||||
? 1
|
||||
: AriaManager.getInstance(mContext).getDownloadConfig().getThreadNum();
|
||||
}
|
||||
|
||||
@Override protected void checkTask() {
|
||||
mConfigFile = new File(CommonUtil.getFileConfigPath(true, mEntity.getFileName()));
|
||||
mTempFile = new File(mEntity.getDownloadPath());
|
||||
|
||||
@@ -28,8 +28,6 @@ import java.io.IOException;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.net.URLDecoder;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 下载文件信息获取
|
||||
@@ -77,7 +75,7 @@ class HttpFileInfoThread implements Runnable {
|
||||
private void handleConnect(HttpURLConnection conn) throws IOException {
|
||||
long len = conn.getContentLength();
|
||||
if (len < 0) {
|
||||
String temp = conn.getHeaderField(mTaskEntity.contentLength);
|
||||
String temp = conn.getHeaderField("Content-Length");
|
||||
len = TextUtils.isEmpty(temp) ? -1 : Long.parseLong(temp);
|
||||
// 某些服务,如果设置了conn.setRequestProperty("Range", "bytes=" + 0 + "-");
|
||||
// 会返回 Content-Range: bytes 0-225427911/225427913
|
||||
@@ -94,7 +92,7 @@ class HttpFileInfoThread implements Runnable {
|
||||
int code = conn.getResponseCode();
|
||||
boolean isComplete = false;
|
||||
if (TextUtils.isEmpty(mEntity.getMd5Code())) {
|
||||
String md5Code = conn.getHeaderField(mTaskEntity.md5Key);
|
||||
String md5Code = conn.getHeaderField("Content-MD5");
|
||||
mEntity.setMd5Code(md5Code);
|
||||
}
|
||||
|
||||
@@ -104,7 +102,7 @@ class HttpFileInfoThread implements Runnable {
|
||||
if (!TextUtils.isEmpty(str) && str.equals("chunked")) {
|
||||
isChunked = true;
|
||||
}
|
||||
String disposition = conn.getHeaderField(mTaskEntity.dispositionKey);
|
||||
String disposition = conn.getHeaderField("Content-Disposition");
|
||||
if (!TextUtils.isEmpty(disposition)) {
|
||||
mEntity.setDisposition(CommonUtil.encryptBASE64(disposition));
|
||||
if (disposition.contains(mTaskEntity.dispositionFileKey)) {
|
||||
@@ -133,10 +131,10 @@ class HttpFileInfoThread implements Runnable {
|
||||
} else if (code == HttpURLConnection.HTTP_MOVED_TEMP
|
||||
|| code == HttpURLConnection.HTTP_MOVED_PERM
|
||||
|| code == HttpURLConnection.HTTP_SEE_OTHER) {
|
||||
mTaskEntity.redirectUrl = conn.getHeaderField(mTaskEntity.redirectUrlKey);
|
||||
mTaskEntity.redirectUrl = conn.getHeaderField("Location");
|
||||
mEntity.setRedirect(true);
|
||||
mEntity.setRedirectUrl(mTaskEntity.redirectUrl);
|
||||
handle302Turn(conn);
|
||||
handle302Turn(conn, mTaskEntity.redirectUrl);
|
||||
} else {
|
||||
failDownload("任务【" + mEntity.getUrl() + "】下载失败,错误码:" + code, true);
|
||||
}
|
||||
@@ -153,9 +151,8 @@ class HttpFileInfoThread implements Runnable {
|
||||
/**
|
||||
* 处理30x跳转
|
||||
*/
|
||||
private void handle302Turn(HttpURLConnection conn) throws IOException {
|
||||
String newUrl = conn.getHeaderField(mTaskEntity.redirectUrlKey);
|
||||
ALog.d(TAG, "30x跳转,location【 " + mTaskEntity.redirectUrlKey + "】" + "新url为【" + newUrl + "】");
|
||||
private void handle302Turn(HttpURLConnection conn, String newUrl) throws IOException {
|
||||
ALog.d(TAG, "30x跳转,新url为【" + newUrl + "】");
|
||||
if (TextUtils.isEmpty(newUrl) || newUrl.equalsIgnoreCase("null") || !newUrl.startsWith(
|
||||
"http")) {
|
||||
if (onFileInfoListener != null) {
|
||||
|
||||
@@ -101,37 +101,17 @@ public abstract class AbsTaskEntity<ENTITY extends AbsEntity> extends DbEntity {
|
||||
*/
|
||||
public RequestEnum requestEnum = RequestEnum.GET;
|
||||
|
||||
/**
|
||||
* 从header中含有的文件md5码信息所需要的key
|
||||
*/
|
||||
public String md5Key = "Content-MD5";
|
||||
|
||||
/**
|
||||
* 是否使用服务器通过content-disposition传递的文件名,内容格式{@code attachment;filename=***}
|
||||
* {@code true} 使用
|
||||
*/
|
||||
public boolean useServerFileName = false;
|
||||
|
||||
/**
|
||||
* 从header中获取文件描述信息所需要的key
|
||||
*/
|
||||
public String dispositionKey = "Content-Disposition";
|
||||
|
||||
/**
|
||||
* 重定向后,从header中获取新url所需要的key
|
||||
*/
|
||||
public String redirectUrlKey = "location";
|
||||
|
||||
/**
|
||||
* 从Disposition获取的文件名说需要的key
|
||||
*/
|
||||
public String dispositionFileKey = "attachment;filename";
|
||||
|
||||
/**
|
||||
* 从header中含有的文件长度信息所需要的key
|
||||
*/
|
||||
public String contentLength = "Content-Length";
|
||||
|
||||
/**
|
||||
* 重定向链接
|
||||
*/
|
||||
|
||||
@@ -49,31 +49,4 @@ public interface IHttpHeaderTarget<TARGET extends ITarget> {
|
||||
* @param requestEnum {@link RequestEnum}
|
||||
*/
|
||||
TARGET setRequestMode(RequestEnum requestEnum);
|
||||
|
||||
/**
|
||||
* 如果你的下载链接的header中含有md5码信息,那么你可以通过设置key,来获取从header获取该md5码信息。
|
||||
* key默认值为:Content-MD5
|
||||
* 获取md5信息:{@link DownloadEntity#getMd5Code()}
|
||||
*/
|
||||
TARGET setHeaderMd5Key(String md5Key);
|
||||
|
||||
/**
|
||||
* 如果你的文件长度是放在header中,那么你需要配置key来让Aria知道正确的文件长度
|
||||
* key默认值为:Content-Length
|
||||
*/
|
||||
TARGET setHeaderContentLengthKey(String contentLength);
|
||||
|
||||
/**
|
||||
* 如果你的下载链接的header中含有文件描述信息,那么你可以通过设置key,来获取从header获取该文件描述信息。
|
||||
* key默认值为:Content-Disposition
|
||||
* 获取文件描述信息:{@link DownloadEntity#getDisposition()}
|
||||
*/
|
||||
TARGET setHeaderDispositionKey(String dispositionKey);
|
||||
|
||||
/**
|
||||
* 从文件描述信息{@link #setHeaderDispositionKey(String)}中含有文件名信息,你可以通过设置key来获取header中的文件名
|
||||
* key默认值为:attachment;filename
|
||||
* 获取文件名信息:{@link DownloadEntity#getServerFileName()}
|
||||
*/
|
||||
TARGET setHeaderDispositionFileKey(String dispositionFileKey);
|
||||
}
|
||||
|
||||
@@ -38,8 +38,8 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
* Created by lyy on 2017/6/4.
|
||||
* 事件调度器,用于处理任务状态的调度
|
||||
*/
|
||||
abstract class AbsSchedulers<TASK_ENTITY extends AbsTaskEntity, TASK extends AbsTask<TASK_ENTITY>, QUEUE extends ITaskQueue<TASK, TASK_ENTITY>>
|
||||
implements ISchedulers<TASK> {
|
||||
abstract class AbsSchedulers<TASK_ENTITY extends AbsTaskEntity, TASK extends AbsTask<TASK_ENTITY>,
|
||||
QUEUE extends ITaskQueue<TASK, TASK_ENTITY>> implements ISchedulers<TASK> {
|
||||
private final String TAG = "AbsSchedulers";
|
||||
|
||||
protected QUEUE mQueue;
|
||||
|
||||
@@ -95,20 +95,4 @@ public class UploadTarget extends BaseNormalTarget<UploadTarget>
|
||||
@Override public UploadTarget setRequestMode(RequestEnum requestEnum) {
|
||||
return mDelegate.setRequestMode(requestEnum);
|
||||
}
|
||||
|
||||
@Override public UploadTarget setHeaderMd5Key(String md5Key) {
|
||||
return mDelegate.setHeaderMd5Key(md5Key);
|
||||
}
|
||||
|
||||
@Override public UploadTarget setHeaderContentLengthKey(String contentLength) {
|
||||
return mDelegate.setHeaderContentLengthKey(contentLength);
|
||||
}
|
||||
|
||||
@Override public UploadTarget setHeaderDispositionKey(String dispositionKey) {
|
||||
return mDelegate.setHeaderDispositionKey(dispositionKey);
|
||||
}
|
||||
|
||||
@Override public UploadTarget setHeaderDispositionFileKey(String dispositionFileKey) {
|
||||
return mDelegate.setHeaderDispositionFileKey(dispositionFileKey);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,7 +69,7 @@ class Uploader extends AbsFileer<UploadEntity, UploadTaskEntity> {
|
||||
|
||||
}
|
||||
|
||||
@Override protected int getNewTaskThreadNum() {
|
||||
@Override protected int setNewTaskThreadNum() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ import java.util.Map;
|
||||
class DBConfig {
|
||||
static Map<String, Class> mapping = new HashMap<>();
|
||||
static String DB_NAME;
|
||||
static int VERSION = 24;
|
||||
static int VERSION = 25;
|
||||
|
||||
static {
|
||||
if (TextUtils.isEmpty(DB_NAME)) {
|
||||
|
||||
@@ -218,7 +218,7 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
|
||||
//.addHeader("Cookie", "BAIDUID=648E5FF020CC69E8DD6F492D1068AAA9:FG=1; BIDUPSID=648E5FF020CC69E8DD6F492D1068AAA9; PSTM=1519099573; BD_UPN=12314753; locale=zh; BDSVRTM=0")
|
||||
.setRequestMode(RequestEnum.GET)
|
||||
.setFilePath(Environment.getExternalStorageDirectory().getPath() + "/ggsg1.apk")
|
||||
//.resetState()
|
||||
.resetState()
|
||||
.start();
|
||||
//.add();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user