AriaLyy 7 years ago
parent d22d7a3e6b
commit 648d539299
  1. 4
      Aria/src/main/java/com/arialyy/aria/core/download/DownloadEntity.java
  2. 11
      Aria/src/main/java/com/arialyy/aria/core/download/DownloadTarget.java
  3. 2
      Aria/src/main/java/com/arialyy/aria/core/download/downloader/HttpFileInfoThread.java
  4. 22
      Aria/src/main/java/com/arialyy/aria/util/CommonUtil.java
  5. 3
      app/src/main/java/com/arialyy/simple/download/SingleTaskActivity.java

@ -18,9 +18,11 @@ package com.arialyy.aria.core.download;
import android.os.Parcel; import android.os.Parcel;
import android.os.Parcelable; import android.os.Parcelable;
import android.text.TextUtils;
import com.arialyy.aria.core.inf.AbsNormalEntity; import com.arialyy.aria.core.inf.AbsNormalEntity;
import com.arialyy.aria.core.inf.AbsTaskEntity; import com.arialyy.aria.core.inf.AbsTaskEntity;
import com.arialyy.aria.orm.Primary; import com.arialyy.aria.orm.Primary;
import com.arialyy.aria.util.CommonUtil;
/** /**
* Created by lyy on 2015/12/25. * Created by lyy on 2015/12/25.
@ -66,7 +68,7 @@ public class DownloadEntity extends AbsNormalEntity implements Parcelable {
} }
public String getDisposition() { public String getDisposition() {
return disposition; return TextUtils.isEmpty(disposition) ? "" : CommonUtil.decryptBASE64(disposition);
} }
public void setDisposition(String disposition) { public void setDisposition(String disposition) {

@ -31,6 +31,7 @@ import java.io.File;
public class DownloadTarget public class DownloadTarget
extends AbsDownloadTarget<DownloadTarget, DownloadEntity, DownloadTaskEntity> { extends AbsDownloadTarget<DownloadTarget, DownloadEntity, DownloadTaskEntity> {
protected String url; protected String url;
DownloadTarget(DownloadEntity entity, String targetName) { DownloadTarget(DownloadEntity entity, String targetName) {
this(entity.getUrl(), targetName); this(entity.getUrl(), targetName);
} }
@ -88,7 +89,6 @@ public class DownloadTarget
super.setHighestPriority(); super.setHighestPriority();
} }
/** /**
* 下载任务是否存在 * 下载任务是否存在
*/ */
@ -126,10 +126,17 @@ public class DownloadTarget
return this; return this;
} }
private DownloadEntity getDownloadEntity() { public DownloadEntity getDownloadEntity() {
return mEntity; return mEntity;
} }
/**
* 从header中获取文件描述信息
*/
public String getContentDisposition() {
return mEntity.getDisposition();
}
/** /**
* 是否在下载 * 是否在下载
*/ */

@ -84,7 +84,7 @@ class HttpFileInfoThread implements Runnable {
String disposition = conn.getHeaderField(mTaskEntity.dispositionKey); String disposition = conn.getHeaderField(mTaskEntity.dispositionKey);
//Map<String, List<String>> headers = conn.getHeaderFields(); //Map<String, List<String>> headers = conn.getHeaderFields();
if (!TextUtils.isEmpty(disposition)) { if (!TextUtils.isEmpty(disposition)) {
mEntity.setDisposition(disposition); mEntity.setDisposition(CommonUtil.encryptBASE64(disposition));
if (disposition.contains(mTaskEntity.dispositionFileKey)) { if (disposition.contains(mTaskEntity.dispositionFileKey)) {
String[] infos = disposition.split("="); String[] infos = disposition.split("=");
mEntity.setServerFileName(URLDecoder.decode(infos[1], "utf-8")); mEntity.setServerFileName(URLDecoder.decode(infos[1], "utf-8"));

@ -21,6 +21,7 @@ import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.net.Uri; import android.net.Uri;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Base64;
import android.util.Log; import android.util.Log;
import com.arialyy.aria.core.AriaManager; import com.arialyy.aria.core.AriaManager;
import com.arialyy.aria.core.command.normal.NormalCmdFactory; import com.arialyy.aria.core.command.normal.NormalCmdFactory;
@ -45,7 +46,6 @@ import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.LinkedHashSet; import java.util.LinkedHashSet;
import java.util.List; import java.util.List;
@ -64,6 +64,26 @@ import java.lang.reflect.WildcardType;
public class CommonUtil { public class CommonUtil {
private static final String TAG = "CommonUtil"; private static final String TAG = "CommonUtil";
/**
* base64 解密字符串
*
* @param str 被加密的字符串
* @return 解密后的字符串
*/
public static String decryptBASE64(String str) {
return new String(Base64.decode(str.getBytes(), Base64.DEFAULT));
}
/**
* base64 加密字符串
*
* @param str 需要加密的字符串
* @return 加密后的字符串
*/
public static String encryptBASE64(String str) {
return Base64.encodeToString(str.getBytes(), Base64.DEFAULT);
}
/** /**
* 字符串编码转换 * 字符串编码转换
*/ */

@ -43,7 +43,8 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
//"http://kotlinlang.org/docs/kotlin-docs.pdf"; //"http://kotlinlang.org/docs/kotlin-docs.pdf";
//"https://atom-installer.github.com/v1.13.0/AtomSetup.exe?s=1484074138&ext=.exe"; //"https://atom-installer.github.com/v1.13.0/AtomSetup.exe?s=1484074138&ext=.exe";
//"http://static.gaoshouyou.com/d/22/94/822260b849944492caadd2983f9bb624.apk"; //"http://static.gaoshouyou.com/d/22/94/822260b849944492caadd2983f9bb624.apk";
"http://static.gaoshouyou.com/d/22/94/822260b849944492caadd2983f9bb624.apk"; //"http://static.gaoshouyou.com/d/22/94/822260b849944492caadd2983f9bb624.apk";
"http://op08k4l50.bkt.clouddn.com/123.mp4";
//"http://down2.xiaoshuofuwuqi.com/d/file/filetxt/20170608/14/%BA%DA%CE%D7%CA%A6%E1%C8%C6%F0.txt"; //"http://down2.xiaoshuofuwuqi.com/d/file/filetxt/20170608/14/%BA%DA%CE%D7%CA%A6%E1%C8%C6%F0.txt";
//"http://tinghuaapp.oss-cn-shanghai.aliyuncs.com/20170612201739607815"; //"http://tinghuaapp.oss-cn-shanghai.aliyuncs.com/20170612201739607815";
//"http://static.gaoshouyou.com/d/36/69/2d3699acfa69e9632262442c46516ad8.apk"; //"http://static.gaoshouyou.com/d/36/69/2d3699acfa69e9632262442c46516ad8.apk";

Loading…
Cancel
Save