Merge pull request #617 from DaveBoy/master
添加文件名适配器接口,修复group中useServerFileName未同步到子task的问题
This commit is contained in:
@@ -20,6 +20,8 @@ import android.text.TextUtils;
|
||||
import com.arialyy.aria.core.common.RequestEnum;
|
||||
import com.arialyy.aria.core.inf.ITaskOption;
|
||||
import com.arialyy.aria.core.processor.IHttpFileLenAdapter;
|
||||
import com.arialyy.aria.core.processor.IHttpFileNameAdapter;
|
||||
|
||||
import java.lang.ref.SoftReference;
|
||||
import java.net.CookieManager;
|
||||
import java.net.Proxy;
|
||||
@@ -81,17 +83,23 @@ public final class HttpTaskOption implements ITaskOption {
|
||||
|
||||
private SoftReference<IHttpFileLenAdapter> fileLenAdapter;
|
||||
|
||||
private SoftReference<IHttpFileNameAdapter> fileNameAdapter;
|
||||
|
||||
public IHttpFileLenAdapter getFileLenAdapter() {
|
||||
return fileLenAdapter == null ? null : fileLenAdapter.get();
|
||||
}
|
||||
|
||||
public IHttpFileNameAdapter getFileNameAdapter() {
|
||||
return fileNameAdapter == null ? null : fileNameAdapter.get();
|
||||
}
|
||||
/**
|
||||
* 如果是匿名内部类,完成后需要将adapter设置为空,否则会出现内存泄漏
|
||||
*/
|
||||
public void setFileLenAdapter(IHttpFileLenAdapter fileLenAdapter) {
|
||||
this.fileLenAdapter = new SoftReference<>(fileLenAdapter);
|
||||
}
|
||||
|
||||
public void setFileNameAdapter(IHttpFileNameAdapter fileNameAdapter) {
|
||||
this.fileNameAdapter = new SoftReference<>(fileNameAdapter);
|
||||
}
|
||||
public Map<String, String> getFormFields() {
|
||||
return formFields;
|
||||
}
|
||||
@@ -179,4 +187,5 @@ public final class HttpTaskOption implements ITaskOption {
|
||||
public void setParams(Map<String, String> params) {
|
||||
this.params = params;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -158,10 +158,21 @@ final class HttpDFileInfoTask implements IInfoTask, Runnable {
|
||||
if (!TextUtils.isEmpty(disposition)) {
|
||||
mEntity.setDisposition(CommonUtil.encryptBASE64(disposition));
|
||||
handleContentDisposition(disposition);
|
||||
} else {
|
||||
ALog.w(TAG, "Content-Disposition对于端字段为空,使用服务器端文件名失败");
|
||||
} else{
|
||||
if(taskOption.getFileNameAdapter()!=null) {
|
||||
String newName =taskOption.getFileNameAdapter().handleFileName(headers,mEntity.getKey());
|
||||
mEntity.setServerFileName(newName);
|
||||
renameFile(newName);
|
||||
}else if(conn.getHeaderField("Content-Type")!=null){
|
||||
String contentType=conn.getHeaderField("Content-Type");
|
||||
String type=contentType.substring(contentType.indexOf(File.separator)+1);
|
||||
String newName =mEntity.getFileName()+File.separator+type;
|
||||
mEntity.setServerFileName(newName);
|
||||
renameFile(newName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CookieManager msCookieManager = new CookieManager();
|
||||
List<String> cookiesHeader = headers.get("Set-Cookie");
|
||||
|
||||
|
||||
@@ -155,6 +155,11 @@ public final class HttpDGInfoTask implements IInfoTask {
|
||||
|
||||
// 设置属性
|
||||
subOption.setFileLenAdapter(groupOption.getFileLenAdapter());
|
||||
subOption.setFileNameAdapter(groupOption.getFileNameAdapter());
|
||||
subOption.setUseServerFileName(groupOption.isUseServerFileName());
|
||||
|
||||
|
||||
subOption.setFileNameAdapter(groupOption.getFileNameAdapter());
|
||||
subOption.setRequestEnum(groupOption.getRequestEnum());
|
||||
subOption.setHeaders(groupOption.getHeaders());
|
||||
subOption.setProxy(groupOption.getProxy());
|
||||
|
||||
Reference in New Issue
Block a user