diff --git a/Aria/src/main/java/com/arialyy/aria/core/delegate/FtpDelegate.java b/Aria/src/main/java/com/arialyy/aria/core/delegate/FtpDelegate.java index 578c478f..c4a830b6 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/delegate/FtpDelegate.java +++ b/Aria/src/main/java/com/arialyy/aria/core/delegate/FtpDelegate.java @@ -31,16 +31,18 @@ public class FtpDelegate headers) { if (headers.size() == 0) { ALog.w(TAG, "设置header失败,map没有header数据"); - return (TARGET) this; + return mTarget; } /* 两个map比较逻辑 @@ -123,7 +126,7 @@ public class HttpHeaderDelegate } private void initTHis() { - mDelegate = new HttpHeaderDelegate<>(mTaskEntity); + mDelegate = new HttpHeaderDelegate<>(this, mTaskEntity); } /** diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/FtpDirDownloadTarget.java b/Aria/src/main/java/com/arialyy/aria/core/download/FtpDirDownloadTarget.java index ffeacb14..cb7b2d01 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/FtpDirDownloadTarget.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/FtpDirDownloadTarget.java @@ -45,7 +45,7 @@ public class FtpDirDownloadTarget extends BaseGroupTarget mTaskEntity.requestType = AbsTaskEntity.D_FTP_DIR; mEntity = mTaskEntity.entity; - mDelegate = new FtpDelegate<>(mTaskEntity); + mDelegate = new FtpDelegate<>(this, mTaskEntity); } @Override protected int getTargetType() { diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/FtpDownloadTarget.java b/Aria/src/main/java/com/arialyy/aria/core/download/FtpDownloadTarget.java index d9b7b54b..518f3142 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/FtpDownloadTarget.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/FtpDownloadTarget.java @@ -51,7 +51,7 @@ public class FtpDownloadTarget extends BaseNormalTarget mTaskEntity.refreshInfo = refreshInfo; mTaskEntity.requestType = AbsTaskEntity.D_FTP; - mDelegate = new FtpDelegate<>(mTaskEntity); + mDelegate = new FtpDelegate<>(this, mTaskEntity); } /** diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/downloader/ConnectionHelp.java b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/ConnectionHelp.java index 6135ec6f..702f253c 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/downloader/ConnectionHelp.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/ConnectionHelp.java @@ -15,6 +15,7 @@ */ package com.arialyy.aria.core.download.downloader; +import android.util.Log; import com.arialyy.aria.core.download.DownloadTaskEntity; import com.arialyy.aria.util.SSLContextUtil; import java.io.IOException; @@ -80,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"); } diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/downloader/HttpFileInfoThread.java b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/HttpFileInfoThread.java index 1a51ab7f..0bfaceb0 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/downloader/HttpFileInfoThread.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/HttpFileInfoThread.java @@ -15,7 +15,9 @@ */ package com.arialyy.aria.core.download.downloader; +import android.location.Address; import android.text.TextUtils; +import android.util.Log; import com.arialyy.aria.core.AriaManager; import com.arialyy.aria.core.common.CompleteInfo; import com.arialyy.aria.core.common.OnFileInfoCallback; @@ -27,7 +29,9 @@ import com.arialyy.aria.util.CommonUtil; import java.io.IOException; import java.io.InputStream; import java.net.HttpURLConnection; +import java.net.InetAddress; import java.net.URL; +import java.net.URLConnection; import java.net.URLDecoder; import java.util.List; import java.util.Map; @@ -58,10 +62,7 @@ class HttpFileInfoThread implements Runnable { conn = ConnectionHelp.setConnectParam(mTaskEntity, conn); conn.setRequestProperty("Range", "bytes=" + 0 + "-"); conn.setConnectTimeout(mConnectTimeOut); - conn.setRequestMethod(mTaskEntity.requestEnum.name); - conn.setDoOutput(true); - conn.setDoInput(true); - conn.setChunkedStreamingMode(0); + //conn.setChunkedStreamingMode(0); conn.connect(); handleConnect(conn); } catch (IOException e) { @@ -83,6 +84,17 @@ class HttpFileInfoThread implements Runnable { if (len < 0) { String temp = conn.getHeaderField(mTaskEntity.contentLength); len = TextUtils.isEmpty(temp) ? -1 : Long.parseLong(temp); + // 某些服务,如果设置了conn.setRequestProperty("Range", "bytes=" + 0 + "-"); + // 会返回 Content-Range: bytes 0-225427911/225427913 + if (len < 0){ + temp = conn.getHeaderField("Content-Range"); + if (TextUtils.isEmpty(temp)){ + len = -1; + }else { + int start = temp.indexOf("/"); + len = Long.parseLong(temp.substring(start + 1, temp.length())); + } + } } int code = conn.getResponseCode(); boolean isComplete = false; @@ -90,20 +102,22 @@ class HttpFileInfoThread implements Runnable { String md5Code = conn.getHeaderField(mTaskEntity.md5Key); mEntity.setMd5Code(md5Code); } - String disposition = conn.getHeaderField(mTaskEntity.dispositionKey); + Map> headers = conn.getHeaderFields(); boolean isChunked = false; //https://my.oschina.net/ososchina/blog/666761 - if (conn.getHeaderField("Transfer-Encoding").equals("chunked")) { + final String str = conn.getHeaderField("Transfer-Encoding"); + if (!TextUtils.isEmpty(str) && str.equals("chunked")) { isChunked = true; - StringBuffer sb = new StringBuffer(); - byte[] buffer = new byte[1024]; - InputStream is = conn.getInputStream(); - int l = 0; + //StringBuffer sb = new StringBuffer(); + //byte[] buffer = new byte[1024]; + //InputStream is = conn.getInputStream(); + //int l = 0; //while (true){ // is.read() //} } + String disposition = conn.getHeaderField(mTaskEntity.dispositionKey); if (!TextUtils.isEmpty(disposition)) { mEntity.setDisposition(CommonUtil.encryptBASE64(disposition)); if (disposition.contains(mTaskEntity.dispositionFileKey)) { diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/downloader/HttpThreadTask.java b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/HttpThreadTask.java index eadf2132..9f0be85c 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/downloader/HttpThreadTask.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/HttpThreadTask.java @@ -90,28 +90,7 @@ final class HttpThreadTask extends AbsThreadTask { - /** * 获取任务状态 * diff --git a/Aria/src/main/java/com/arialyy/aria/core/upload/FtpUploadTarget.java b/Aria/src/main/java/com/arialyy/aria/core/upload/FtpUploadTarget.java index 8892c8b8..34922b45 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/upload/FtpUploadTarget.java +++ b/Aria/src/main/java/com/arialyy/aria/core/upload/FtpUploadTarget.java @@ -21,10 +21,8 @@ import com.arialyy.aria.core.command.normal.NormalCmdFactory; import com.arialyy.aria.core.delegate.FtpDelegate; import com.arialyy.aria.core.inf.AbsTaskEntity; import com.arialyy.aria.core.inf.IFtpTarget; -import com.arialyy.aria.core.manager.TEManager; import com.arialyy.aria.util.CheckUtil; import com.arialyy.aria.util.CommonUtil; -import java.io.File; /** * Created by Aria.Lao on 2017/7/27. @@ -43,7 +41,7 @@ public class FtpUploadTarget extends BaseNormalTarget private void initTask(String filePath) { initTarget(filePath); mTaskEntity.requestType = AbsTaskEntity.U_FTP; - mDelegate = new FtpDelegate<>(mTaskEntity); + mDelegate = new FtpDelegate<>(this, mTaskEntity); } /** diff --git a/Aria/src/main/java/com/arialyy/aria/core/upload/UploadTarget.java b/Aria/src/main/java/com/arialyy/aria/core/upload/UploadTarget.java index eeacbfd9..1fb08fb7 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/upload/UploadTarget.java +++ b/Aria/src/main/java/com/arialyy/aria/core/upload/UploadTarget.java @@ -43,7 +43,7 @@ public class UploadTarget extends BaseNormalTarget //http暂时不支持断点上传 mTaskEntity.isSupportBP = false; mTaskEntity.requestType = AbsTaskEntity.U_HTTP; - mDelegate = new HttpHeaderDelegate<>(mTaskEntity); + mDelegate = new HttpHeaderDelegate<>(this, mTaskEntity); } @Override public UploadTarget setUploadUrl(@NonNull String uploadUrl) { diff --git a/AriaFtpPlug/src/main/java/org/apache/commons/net/ftp/parser/MacOsPeterFTPEntryParser.java b/AriaFtpPlug/src/main/java/org/apache/commons/net/ftp/parser/MacOsPeterFTPEntryParser.java index fd96c8d0..5752a9b9 100644 --- a/AriaFtpPlug/src/main/java/org/apache/commons/net/ftp/parser/MacOsPeterFTPEntryParser.java +++ b/AriaFtpPlug/src/main/java/org/apache/commons/net/ftp/parser/MacOsPeterFTPEntryParser.java @@ -29,7 +29,8 @@ import org.apache.commons.net.ftp.FTPFile; * @see org.apache.commons.net.ftp.FTPFileEntryParser FTPFileEntryParser (for usage instructions) * @since 3.1 */ -public class MacOsPeterFTPEntryParser extends ConfigurableFTPFileEntryParserImpl { +public class +MacOsPeterFTPEntryParser extends ConfigurableFTPFileEntryParserImpl { static final String DEFAULT_DATE_FORMAT = "MMM d yyyy"; //Nov 9 2001 diff --git a/DEV_LOG.md b/DEV_LOG.md index b032d00e..f69f117e 100644 --- a/DEV_LOG.md +++ b/DEV_LOG.md @@ -1,6 +1,7 @@ ## 开发日志 + v_3.3.16 - 修复一个activity启动多次,无法进行回掉的bug https://github.com/AriaLyy/Aria/issues/200 + - 优化target代码结构 + v_3.3.14 - 修复ftp上传和下载的兼容性问题 - 如果url中的path有"//"将替换为"/" diff --git a/app/src/main/assets/aria_config.xml b/app/src/main/assets/aria_config.xml index ce92a575..7268c227 100644 --- a/app/src/main/assets/aria_config.xml +++ b/app/src/main/assets/aria_config.xml @@ -5,13 +5,13 @@ - + - + diff --git a/app/src/main/java/com/arialyy/simple/download/SingleTaskActivity.java b/app/src/main/java/com/arialyy/simple/download/SingleTaskActivity.java index 96fc98ac..be887ca3 100644 --- a/app/src/main/java/com/arialyy/simple/download/SingleTaskActivity.java +++ b/app/src/main/java/com/arialyy/simple/download/SingleTaskActivity.java @@ -29,6 +29,7 @@ import android.widget.Toast; import butterknife.Bind; import com.arialyy.annotations.Download; import com.arialyy.aria.core.Aria; +import com.arialyy.aria.core.common.RequestEnum; import com.arialyy.aria.core.download.DownloadTarget; import com.arialyy.aria.core.download.DownloadTask; import com.arialyy.aria.core.inf.IEntity; @@ -61,8 +62,9 @@ public class SingleTaskActivity extends BaseActivity { //"http://qudao.5535.cn/one/game.html?game=531&cpsuser=xiaoeryu2"; //"https://bogoe-res.mytbz.com/tbzengsong/If You're Happy.mp3"; //"http://ozr0ucjs5.bkt.clouddn.com/51_box-104_20180131202610.apk"; - "http://kf.lyfz.net/api/v1/we_chat/Business/getMaterial?company_id=51454009d703c86c91353f61011ecf2f&appid=wx88c6052d06eaaf7d&media_id=qpkQb72KqNkZhBNIUw7asF0LuJouXCTBd3A-rS2bYl7H4kvTZstEXD3F-pDVeqA-&type=3"; + //"http://kf.lyfz.net/api/v1/we_chat/Business/getMaterial?company_id=51454009d703c86c91353f61011ecf2f&appid=wx88c6052d06eaaf7d&media_id=qpkQb72KqNkZhBNIUw7asF0LuJouXCTBd3A-rS2bYl7H4kvTZstEXD3F-pDVeqA-&type=3"; //"https://www.baidu.com/link?url=_LFCuTPtnzFxVJByJ504QymRywIA1Z_T5xUxe9ZLuxcGM0C_RcdpWyB1eGjbJC-e5wv5wAKM4WmLMAS5KeF6EZJHB8Va3YqZUiaErqK_pxm&wd=&eqid=e8583fe70002d126000000065a99f864"; + "http://58.210.9.131/tpk/sipgt/TDLYZTGH.tpk"; @Bind(R.id.start) Button mStart; @Bind(R.id.stop) Button mStop; @Bind(R.id.cancel) Button mCancel; @@ -230,8 +232,8 @@ public class SingleTaskActivity extends BaseActivity { .addHeader("Accept-Encoding", "gzip, deflate") .addHeader("DNT", "1") //.addHeader("Cookie", "BAIDUID=648E5FF020CC69E8DD6F492D1068AAA9:FG=1; BIDUPSID=648E5FF020CC69E8DD6F492D1068AAA9; PSTM=1519099573; BD_UPN=12314753; locale=zh; BDSVRTM=0") - //.setRequestMode(RequestEnum.POST) - .setDownloadPath(Environment.getExternalStorageDirectory().getPath() + "/ggsg1.apk") + .setRequestMode(RequestEnum.GET) + .setFilePath(Environment.getExternalStorageDirectory().getPath() + "/ggsg1.apk") .resetState() .start(); //.add();