diff --git a/Aria/src/main/java/com/arialyy/aria/core/common/BaseListener.java b/Aria/src/main/java/com/arialyy/aria/core/common/BaseListener.java index 1fb9d49e..692d703a 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/common/BaseListener.java +++ b/Aria/src/main/java/com/arialyy/aria/core/common/BaseListener.java @@ -110,7 +110,7 @@ public abstract class BaseListener implements ITargetHandler { - private final String TAG = "FTPSDelegate"; - private TARGET mTarget; - private FtpUrlEntity mUrlEntity; - - public FTPSDelegate(TARGET target) { - mTarget = target; - mUrlEntity = mTarget.getTaskWrapper().asFtp().getUrlEntity(); - } - - /** - * 设置协议类型 - * - * @param protocol {@link ProtocolType} - */ - public FTPSDelegate setProtocol(@ProtocolType String protocol) { - if (TextUtils.isEmpty(protocol)) { - throw new NullPointerException("协议为空"); - } - mUrlEntity.protocol = protocol; - return this; - } - - /** - * 设置证书别名 - * - * @param keyAlias 别名 - */ - public FTPSDelegate setAlias(String keyAlias) { - if (TextUtils.isEmpty(keyAlias)) { - throw new NullPointerException("别名为空"); - } - mUrlEntity.keyAlias = keyAlias; - return this; - } - - /** - * 设置证书密码 - * - * @param storePass 私钥密码 - */ - public FTPSDelegate setStorePass(String storePass) { - if (TextUtils.isEmpty(storePass)) { - throw new NullPointerException("证书密码为空"); - } - mUrlEntity.storePass = storePass; - return this; - } - - /** - * 设置证书路径 - * - * @param storePath 证书路径 - */ - public FTPSDelegate setStorePath(String storePath) { - if (TextUtils.isEmpty(storePath)) { - throw new NullPointerException("证书路径为空"); - } - mUrlEntity.storePath = storePath; - return this; - } - - @Override public void add() { - mTarget.add(); - } - - @Override public void start() { - mTarget.start(); - } - - @Override public void stop() { - mTarget.stop(); - } - - @Override public void resume() { - mTarget.resume(); - } - - @Override public void cancel() { - mTarget.cancel(); - } - - @Override public void save() { - mTarget.save(); - } - - @Override public void cancel(boolean removeFile) { - mTarget.cancel(removeFile); - } - - @Override public void reTry() { - mTarget.reTry(); - } - - @Override public void reStart() { - mTarget.reStart(); - } -} +/* + * 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.common.ftp; + +import android.text.TextUtils; +import com.arialyy.aria.core.FtpUrlEntity; +import com.arialyy.aria.core.common.ProtocolType; +import com.arialyy.aria.core.inf.AbsTarget; +import com.arialyy.aria.core.inf.ITargetHandler; + +/** + * D_FTP SSL/TSL 参数委托 + */ +public class FTPSDelegate implements ITargetHandler { + private final String TAG = "FTPSDelegate"; + private TARGET mTarget; + private FtpUrlEntity mUrlEntity; + + public FTPSDelegate(TARGET target) { + mTarget = target; + mUrlEntity = mTarget.getTaskWrapper().asFtp().getUrlEntity(); + } + + /** + * 设置协议类型 + * + * @param protocol {@link ProtocolType} + */ + public FTPSDelegate setProtocol(@ProtocolType String protocol) { + if (TextUtils.isEmpty(protocol)) { + throw new NullPointerException("协议为空"); + } + mUrlEntity.protocol = protocol; + return this; + } + + /** + * 设置证书别名 + * + * @param keyAlias 别名 + */ + public FTPSDelegate setAlias(String keyAlias) { + if (TextUtils.isEmpty(keyAlias)) { + throw new NullPointerException("别名为空"); + } + mUrlEntity.keyAlias = keyAlias; + return this; + } + + /** + * 设置证书密码 + * + * @param storePass 私钥密码 + */ + public FTPSDelegate setStorePass(String storePass) { + if (TextUtils.isEmpty(storePass)) { + throw new NullPointerException("证书密码为空"); + } + mUrlEntity.storePass = storePass; + return this; + } + + /** + * 设置证书路径 + * + * @param storePath 证书路径 + */ + public FTPSDelegate setStorePath(String storePath) { + if (TextUtils.isEmpty(storePath)) { + throw new NullPointerException("证书路径为空"); + } + mUrlEntity.storePath = storePath; + return this; + } + + @Override public void add() { + mTarget.add(); + } + + @Override public void start() { + mTarget.start(); + } + + @Override public void stop() { + mTarget.stop(); + } + + @Override public void resume() { + mTarget.resume(); + } + + @Override public void cancel() { + mTarget.cancel(); + } + + @Override public void save() { + mTarget.save(); + } + + @Override public void cancel(boolean removeFile) { + mTarget.cancel(removeFile); + } + + @Override public void reTry() { + mTarget.reTry(); + } + + @Override public void reStart() { + mTarget.reStart(); + } +} diff --git a/Aria/src/main/java/com/arialyy/aria/core/common/http/HttpHeaderDelegate.java b/Aria/src/main/java/com/arialyy/aria/core/common/http/HttpHeaderDelegate.java index 4b6a0f7e..1666eda5 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/common/http/HttpHeaderDelegate.java +++ b/Aria/src/main/java/com/arialyy/aria/core/common/http/HttpHeaderDelegate.java @@ -29,7 +29,7 @@ import java.util.Set; /** * Created by laoyuyu on 2018/3/9. - * HTTP header参数设置委托类 + * D_HTTP header参数设置委托类 */ public class HttpHeaderDelegate implements IHttpHeaderDelegate { diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/AbsDTarget.java b/Aria/src/main/java/com/arialyy/aria/core/download/AbsDTarget.java index 121c1d37..633c6ca1 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/AbsDTarget.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/AbsDTarget.java @@ -1,57 +1,57 @@ -/* - * 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.download; - -import com.arialyy.aria.core.AriaManager; -import com.arialyy.aria.core.command.normal.NormalCmdFactory; -import com.arialyy.aria.core.inf.AbsTarget; -import com.arialyy.aria.util.CommonUtil; - -/** - * Created by lyy on 2017/2/28. - */ -abstract class AbsDTarget extends AbsTarget { - - /** - * 更新下载url - * - * @param newUrl 新的下载url - */ - public abstract TARGET updateUrl(String newUrl); - - /** - * 将任务设置为最高优先级任务,最高优先级任务有以下特点: - * 1、在下载队列中,有且只有一个最高优先级任务 - * 2、最高优先级任务会一直存在,直到用户手动暂停或任务完成 - * 3、任务调度器不会暂停最高优先级任务 - * 4、用户手动暂停或任务完成后,第二次重新执行该任务,该命令将失效 - * 5、如果下载队列中已经满了,则会停止队尾的任务,当高优先级任务完成后,该队尾任务将自动执行 - * 6、把任务设置为最高优先级任务后,将自动执行任务,不需要重新调用start()启动任务 - */ - public void setHighestPriority() { - if (checkEntity()) { - AriaManager.getInstance(AriaManager.APP) - .setCmd( - CommonUtil.createNormalCmd(getTaskWrapper(), NormalCmdFactory.TASK_HIGHEST_PRIORITY, - checkTaskType())) - .exe(); - } - } - - @Override public DownloadEntity getEntity() { - return (DownloadEntity) super.getEntity(); - } -} +/* + * 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.download; + +import com.arialyy.aria.core.AriaManager; +import com.arialyy.aria.core.command.normal.NormalCmdFactory; +import com.arialyy.aria.core.inf.AbsTarget; +import com.arialyy.aria.util.CommonUtil; + +/** + * Created by lyy on 2017/2/28. + */ +abstract class AbsDTarget extends AbsTarget { + + /** + * 更新下载url + * + * @param newUrl 新的下载url + */ + public abstract TARGET updateUrl(String newUrl); + + /** + * 将任务设置为最高优先级任务,最高优先级任务有以下特点: + * 1、在下载队列中,有且只有一个最高优先级任务 + * 2、最高优先级任务会一直存在,直到用户手动暂停或任务完成 + * 3、任务调度器不会暂停最高优先级任务 + * 4、用户手动暂停或任务完成后,第二次重新执行该任务,该命令将失效 + * 5、如果下载队列中已经满了,则会停止队尾的任务,当高优先级任务完成后,该队尾任务将自动执行 + * 6、把任务设置为最高优先级任务后,将自动执行任务,不需要重新调用start()启动任务 + */ + public void setHighestPriority() { + if (checkConfig()) { + AriaManager.getInstance(AriaManager.APP) + .setCmd( + CommonUtil.createNormalCmd(getTaskWrapper(), NormalCmdFactory.TASK_HIGHEST_PRIORITY, + checkTaskType())) + .exe(); + } + } + + @Override public DownloadEntity getEntity() { + return (DownloadEntity) super.getEntity(); + } +} diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/DNormalDelegate.java b/Aria/src/main/java/com/arialyy/aria/core/download/DNormalDelegate.java index 6f5e3d38..742c6124 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/DNormalDelegate.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/DNormalDelegate.java @@ -22,6 +22,7 @@ import com.arialyy.aria.core.manager.TaskWrapperManager; import com.arialyy.aria.core.queue.DownloadTaskQueue; import com.arialyy.aria.orm.DbEntity; import com.arialyy.aria.util.ALog; +import com.arialyy.aria.util.CheckUtil; import com.arialyy.aria.util.CommonUtil; import java.io.File; @@ -113,10 +114,10 @@ class DNormalDelegate implements INormalTarget { } File file = new File(filePath); if (file.isDirectory()) { - if (mTarget.getTargetType() == ITargetHandler.HTTP) { + if (mTarget.getTargetType() == ITargetHandler.D_HTTP) { ALog.e(TAG, "下载失败,保存路径【" + filePath + "】不能为文件夹,路径需要是完整的文件路径,如:/mnt/sdcard/game.zip"); return false; - } else if (mTarget.getTargetType() == ITargetHandler.FTP) { + } else if (mTarget.getTargetType() == ITargetHandler.D_FTP) { filePath += mEntity.getFileName(); } } else { @@ -167,7 +168,7 @@ class DNormalDelegate implements INormalTarget { if (TextUtils.isEmpty(url)) { ALog.e(TAG, "下载失败,url为null"); return false; - } else if (!url.startsWith("http") && !url.startsWith("ftp")) { + } else if (!CheckUtil.checkUrlNotThrow(url)) { ALog.e(TAG, "下载失败,url【" + url + "】错误"); return false; } diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadTarget.java b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadTarget.java index c101c7c4..6c6c222a 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadTarget.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadTarget.java @@ -118,7 +118,7 @@ public class DownloadTarget extends AbsDTarget } @Override public int getTargetType() { - return HTTP; + return D_HTTP; } /** 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 e4461d0d..632aa368 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 @@ -1,155 +1,155 @@ -/* - * 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.download; - -import android.support.annotation.CheckResult; -import android.support.annotation.NonNull; -import android.text.TextUtils; -import com.arialyy.aria.core.common.ftp.FTPSDelegate; -import com.arialyy.aria.core.common.ftp.FtpDelegate; -import com.arialyy.aria.core.inf.AbsTaskWrapper; -import com.arialyy.aria.core.inf.IFtpTarget; -import com.arialyy.aria.util.ALog; -import com.arialyy.aria.util.CommonUtil; -import java.net.Proxy; - -/** - * Created by lyy on 2016/12/5. - * https://github.com/AriaLyy/Aria - */ -public class FtpDownloadTarget extends AbsDTarget - implements IFtpTarget { - private FtpDelegate mFtpDelegate; - private DNormalDelegate mNormalDelegate; - - FtpDownloadTarget(DownloadEntity entity, String targetName) { - this(entity.getUrl(), targetName); - } - - FtpDownloadTarget(String url, String targetName) { - mNormalDelegate = new DNormalDelegate<>(this, url, targetName); - init(); - } - - private void init() { - int lastIndex = mNormalDelegate.getUrl().lastIndexOf("/"); - getEntity().setFileName(mNormalDelegate.getUrl().substring(lastIndex + 1)); - getTaskWrapper().asFtp().setUrlEntity(CommonUtil.getFtpUrlInfo(mNormalDelegate.getUrl())); - getTaskWrapper().setRequestType(AbsTaskWrapper.D_FTP); - - mFtpDelegate = new FtpDelegate<>(this); - } - - /** - * 是否是FTPS协议 - * 如果是FTPS协议,需要使用{@link FTPSDelegate#setStorePath(String)} 、{@link FTPSDelegate#setAlias(String)} - * 设置证书信息 - */ - @CheckResult - public FTPSDelegate asFtps() { - getTaskWrapper().asFtp().getUrlEntity().isFtps = true; - return new FTPSDelegate<>(this); - } - - @Override protected boolean checkEntity() { - if (getTaskWrapper().asFtp().getUrlEntity().isFtps) { - if (TextUtils.isEmpty(getTaskWrapper().asFtp().getUrlEntity().storePath)) { - ALog.e(TAG, "证书路径为空"); - return false; - } - if (TextUtils.isEmpty(getTaskWrapper().asFtp().getUrlEntity().keyAlias)) { - ALog.e(TAG, "证书别名为空"); - return false; - } - } - return mNormalDelegate.checkEntity(); - } - - @Override public boolean isRunning() { - return mNormalDelegate.isRunning(); - } - - @Override public boolean taskExists() { - return mNormalDelegate.taskExists(); - } - - /** - * 设置文件保存文件夹路径 - * - * @param filePath 文件保存路径 - * @deprecated {@link #setFilePath(String)} 请使用这个api - */ - @Deprecated - @CheckResult - public FtpDownloadTarget setDownloadPath(@NonNull String filePath) { - return setFilePath(filePath); - } - - /** - * 设置文件保存文件夹路径 - * 关于文件名: - * 1、如果保存路径是该文件的保存路径,如:/mnt/sdcard/file.zip,则使用路径中的文件名file.zip - * 2、如果保存路径是文件夹路径,如:/mnt/sdcard/,则使用FTP服务器该文件的文件名 - */ - @CheckResult - public FtpDownloadTarget setFilePath(@NonNull String filePath) { - mNormalDelegate.setTempFilePath(filePath); - return this; - } - - /** - * 设置文件存储路径,如果需要修改新的文件名,修改路径便可。 - * 如:原文件路径 /mnt/sdcard/test.zip - * 如果需要将test.zip改为game.zip,只需要重新设置文件路径为:/mnt/sdcard/game.zip - * - * @param filePath 路径必须为文件路径,不能为文件夹路径 - * @param forceDownload {@code true}强制下载,不考虑文件路径是否被占用 - */ - @CheckResult - public FtpDownloadTarget setFilePath(@NonNull String filePath, boolean forceDownload) { - mNormalDelegate.setTempFilePath(filePath); - mNormalDelegate.setForceDownload(forceDownload); - return this; - } - - @Override public int getTargetType() { - return FTP; - } - - @CheckResult - @Override public FtpDownloadTarget charSet(String charSet) { - return mFtpDelegate.charSet(charSet); - } - - @CheckResult - @Override public FtpDownloadTarget login(String userName, String password) { - return mFtpDelegate.login(userName, password); - } - - @CheckResult - @Override public FtpDownloadTarget login(String userName, String password, String account) { - return mFtpDelegate.login(userName, password, account); - } - - @CheckResult - @Override public FtpDownloadTarget setProxy(Proxy proxy) { - return mFtpDelegate.setProxy(proxy); - } - - @Override public FtpDownloadTarget updateUrl(String newUrl) { - return mNormalDelegate.updateUrl(newUrl); - } -} +/* + * 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.download; + +import android.support.annotation.CheckResult; +import android.support.annotation.NonNull; +import android.text.TextUtils; +import com.arialyy.aria.core.common.ftp.FTPSDelegate; +import com.arialyy.aria.core.common.ftp.FtpDelegate; +import com.arialyy.aria.core.inf.AbsTaskWrapper; +import com.arialyy.aria.core.inf.IFtpTarget; +import com.arialyy.aria.util.ALog; +import com.arialyy.aria.util.CommonUtil; +import java.net.Proxy; + +/** + * Created by lyy on 2016/12/5. + * https://github.com/AriaLyy/Aria + */ +public class FtpDownloadTarget extends AbsDTarget + implements IFtpTarget { + private FtpDelegate mFtpDelegate; + private DNormalDelegate mNormalDelegate; + + FtpDownloadTarget(DownloadEntity entity, String targetName) { + this(entity.getUrl(), targetName); + } + + FtpDownloadTarget(String url, String targetName) { + mNormalDelegate = new DNormalDelegate<>(this, url, targetName); + init(); + } + + private void init() { + int lastIndex = mNormalDelegate.getUrl().lastIndexOf("/"); + getEntity().setFileName(mNormalDelegate.getUrl().substring(lastIndex + 1)); + getTaskWrapper().asFtp().setUrlEntity(CommonUtil.getFtpUrlInfo(mNormalDelegate.getUrl())); + getTaskWrapper().setRequestType(AbsTaskWrapper.D_FTP); + + mFtpDelegate = new FtpDelegate<>(this); + } + + /** + * 是否是FTPS协议 + * 如果是FTPS协议,需要使用{@link FTPSDelegate#setStorePath(String)} 、{@link FTPSDelegate#setAlias(String)} + * 设置证书信息 + */ + @CheckResult + public FTPSDelegate asFtps() { + getTaskWrapper().asFtp().getUrlEntity().isFtps = true; + return new FTPSDelegate<>(this); + } + + @Override protected boolean checkEntity() { + if (getTaskWrapper().asFtp().getUrlEntity().isFtps) { + if (TextUtils.isEmpty(getTaskWrapper().asFtp().getUrlEntity().storePath)) { + ALog.e(TAG, "证书路径为空"); + return false; + } + if (TextUtils.isEmpty(getTaskWrapper().asFtp().getUrlEntity().keyAlias)) { + ALog.e(TAG, "证书别名为空"); + return false; + } + } + return mNormalDelegate.checkEntity(); + } + + @Override public boolean isRunning() { + return mNormalDelegate.isRunning(); + } + + @Override public boolean taskExists() { + return mNormalDelegate.taskExists(); + } + + /** + * 设置文件保存文件夹路径 + * + * @param filePath 文件保存路径 + * @deprecated {@link #setFilePath(String)} 请使用这个api + */ + @Deprecated + @CheckResult + public FtpDownloadTarget setDownloadPath(@NonNull String filePath) { + return setFilePath(filePath); + } + + /** + * 设置文件保存文件夹路径 + * 关于文件名: + * 1、如果保存路径是该文件的保存路径,如:/mnt/sdcard/file.zip,则使用路径中的文件名file.zip + * 2、如果保存路径是文件夹路径,如:/mnt/sdcard/,则使用FTP服务器该文件的文件名 + */ + @CheckResult + public FtpDownloadTarget setFilePath(@NonNull String filePath) { + mNormalDelegate.setTempFilePath(filePath); + return this; + } + + /** + * 设置文件存储路径,如果需要修改新的文件名,修改路径便可。 + * 如:原文件路径 /mnt/sdcard/test.zip + * 如果需要将test.zip改为game.zip,只需要重新设置文件路径为:/mnt/sdcard/game.zip + * + * @param filePath 路径必须为文件路径,不能为文件夹路径 + * @param forceDownload {@code true}强制下载,不考虑文件路径是否被占用 + */ + @CheckResult + public FtpDownloadTarget setFilePath(@NonNull String filePath, boolean forceDownload) { + mNormalDelegate.setTempFilePath(filePath); + mNormalDelegate.setForceDownload(forceDownload); + return this; + } + + @Override public int getTargetType() { + return D_FTP; + } + + @CheckResult + @Override public FtpDownloadTarget charSet(String charSet) { + return mFtpDelegate.charSet(charSet); + } + + @CheckResult + @Override public FtpDownloadTarget login(String userName, String password) { + return mFtpDelegate.login(userName, password); + } + + @CheckResult + @Override public FtpDownloadTarget login(String userName, String password, String account) { + return mFtpDelegate.login(userName, password, account); + } + + @CheckResult + @Override public FtpDownloadTarget setProxy(Proxy proxy) { + return mFtpDelegate.setProxy(proxy); + } + + @Override public FtpDownloadTarget updateUrl(String newUrl) { + return mNormalDelegate.updateUrl(newUrl); + } +} diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/HttpGroupDelegate.java b/Aria/src/main/java/com/arialyy/aria/core/download/HttpGroupDelegate.java index 966f4543..be8853ff 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/HttpGroupDelegate.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/HttpGroupDelegate.java @@ -22,6 +22,7 @@ import com.arialyy.aria.orm.DbEntity; import com.arialyy.aria.util.ALog; import com.arialyy.aria.util.CommonUtil; import java.util.ArrayList; +import java.util.Arrays; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -61,11 +62,11 @@ class HttpGroupDelegate extends AbsGroupDelegate { @CheckResult DownloadGroupTarget setSubFileName(List subTaskFileName) { if (subTaskFileName == null || subTaskFileName.isEmpty()) { - ALog.e(TAG, "修改子任务的文件名失败:列表为null"); + ALog.w(TAG, "修改子任务的文件名失败:列表为null"); return getTarget(); } if (subTaskFileName.size() != getTaskWrapper().getSubTaskWrapper().size()) { - ALog.e(TAG, "修改子任务的文件名失败:子任务文件名列表数量和子任务的数量不匹配"); + ALog.w(TAG, "修改子任务的文件名失败:子任务文件名列表数量和子任务的数量不匹配"); return getTarget(); } mSubNameTemp.clear(); @@ -179,6 +180,19 @@ class HttpGroupDelegate extends AbsGroupDelegate { ALog.e(TAG, "下载失败,子任务下载列表为null"); return false; } + + Set repeated = new HashSet<>(); + List results = new ArrayList<>(); + for (String url : mUrls) { + if (!repeated.add(url)) { + results.add(url); + } + } + if (!results.isEmpty()) { + ALog.e(TAG, String.format("组合任务中有url重复,重复的url:%s", Arrays.toString(results.toArray()))); + return false; + } + Set delItem = new HashSet<>(); int i = 0; @@ -188,7 +202,6 @@ class HttpGroupDelegate extends AbsGroupDelegate { delItem.add(i); continue; } else if (!url.startsWith("http")) { - //} else if (!url.startsWith("http") && !url.startsWith("ftp")) { ALog.e(TAG, "子任务url【" + url + "】错误,即将删除该子任务。"); delItem.add(i); continue; diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/group/AbsGroupUtil.java b/Aria/src/main/java/com/arialyy/aria/core/download/group/AbsGroupUtil.java index f960c882..b5e54219 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/group/AbsGroupUtil.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/group/AbsGroupUtil.java @@ -41,7 +41,7 @@ public abstract class AbsGroupUtil implements IUtil, Runnable { */ int FTP_DIR = 0xa1; /** - * HTTP 任务组 + * D_HTTP 任务组 */ int HTTP_GROUP = 0xa2; diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/group/DownloadGroupUtil.java b/Aria/src/main/java/com/arialyy/aria/core/download/group/DownloadGroupUtil.java index 78c9a6b2..a953975f 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/group/DownloadGroupUtil.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/group/DownloadGroupUtil.java @@ -148,7 +148,7 @@ public class DownloadGroupUtil extends AbsGroupUtil implements IUtil { mGTWrapper.asHttp().setFileLenAdapter(null); synchronized (LOCK) { - LOCK.notify(); + LOCK.notifyAll(); } } diff --git a/Aria/src/main/java/com/arialyy/aria/core/inf/AbsTarget.java b/Aria/src/main/java/com/arialyy/aria/core/inf/AbsTarget.java index f36cdeda..bd41322e 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/inf/AbsTarget.java +++ b/Aria/src/main/java/com/arialyy/aria/core/inf/AbsTarget.java @@ -15,6 +15,8 @@ */ package com.arialyy.aria.core.inf; +import android.os.Handler; +import android.os.Looper; import android.support.annotation.CheckResult; import android.text.TextUtils; import com.arialyy.aria.core.AriaManager; @@ -25,6 +27,10 @@ import com.arialyy.aria.core.download.DGTaskWrapper; import com.arialyy.aria.core.download.DownloadGroupEntity; import com.arialyy.aria.core.download.DTaskWrapper; import com.arialyy.aria.core.manager.TaskWrapperManager; +import com.arialyy.aria.core.scheduler.DownloadGroupSchedulers; +import com.arialyy.aria.core.scheduler.DownloadSchedulers; +import com.arialyy.aria.core.scheduler.ISchedulers; +import com.arialyy.aria.core.scheduler.UploadSchedulers; import com.arialyy.aria.core.upload.UTaskWrapper; import com.arialyy.aria.util.ALog; import com.arialyy.aria.util.CommonUtil; @@ -196,11 +202,41 @@ public abstract class AbsTarget implements ITargetHand return taskType; } + /** + * 如果检查实体失败,将错误回调 + */ + protected boolean checkConfig() { + boolean b = checkEntity(); + ISchedulers schedulers = getScheduler(); + if (!b && schedulers != null) { + new Handler(Looper.getMainLooper(), schedulers).obtainMessage(ISchedulers.FAIL, + new TempTask(mTaskWrapper, mEntity)).sendToTarget(); + } + + return b; + } + + private ISchedulers getScheduler() { + int type = getTargetType(); + switch (type) { + case D_FTP: + case D_HTTP: + return DownloadSchedulers.getInstance(); + case U_FTP: + case U_HTTP: + return UploadSchedulers.getInstance(); + case GROUP_HTTP: + case GROUP_FTP_DIR: + return DownloadGroupSchedulers.getInstance(); + } + return null; + } + /** * 保存修改 */ @Override public void save() { - if (!checkEntity()) { + if (!checkConfig()) { ALog.e(TAG, "保存修改失败"); } else { ALog.i(TAG, "保存成功"); @@ -224,7 +260,8 @@ public abstract class AbsTarget implements ITargetHand /** * 设置target类型 * - * @return {@link #HTTP}、{@link #FTP}、{@link #GROUP_HTTP}、{@link #GROUP_FTP_DIR} + * @return {@link #D_HTTP}、{@link #U_HTTP}、{@link #D_FTP}、{@link #U_FTP}、{@link + * #GROUP_HTTP}、{@link #GROUP_FTP_DIR} */ public abstract int getTargetType(); @@ -232,7 +269,7 @@ public abstract class AbsTarget implements ITargetHand * 添加任务 */ @Override public void add() { - if (checkEntity()) { + if (checkConfig()) { AriaManager.getInstance(AriaManager.APP) .setCmd(CommonUtil.createNormalCmd(getTaskWrapper(), NormalCmdFactory.TASK_CREATE, checkTaskType())) @@ -244,7 +281,7 @@ public abstract class AbsTarget implements ITargetHand * 开始任务 */ @Override public void start() { - if (checkEntity()) { + if (checkConfig()) { AriaManager.getInstance(AriaManager.APP) .setCmd( CommonUtil.createNormalCmd(mTaskWrapper, NormalCmdFactory.TASK_START, @@ -259,13 +296,13 @@ public abstract class AbsTarget implements ITargetHand * @see #stop() */ @Deprecated public void pause() { - if (checkEntity()) { + if (checkConfig()) { stop(); } } @Override public void stop() { - if (checkEntity()) { + if (checkConfig()) { AriaManager.getInstance(AriaManager.APP) .setCmd( CommonUtil.createNormalCmd(mTaskWrapper, NormalCmdFactory.TASK_STOP, checkTaskType())) @@ -277,7 +314,7 @@ public abstract class AbsTarget implements ITargetHand * 恢复任务 */ @Override public void resume() { - if (checkEntity()) { + if (checkConfig()) { AriaManager.getInstance(AriaManager.APP) .setCmd( CommonUtil.createNormalCmd(mTaskWrapper, NormalCmdFactory.TASK_START, @@ -290,7 +327,7 @@ public abstract class AbsTarget implements ITargetHand * 删除任务 */ @Override public void cancel() { - if (checkEntity()) { + if (checkConfig()) { AriaManager.getInstance(AriaManager.APP) .setCmd(CommonUtil.createNormalCmd(mTaskWrapper, NormalCmdFactory.TASK_CANCEL, checkTaskType())) @@ -302,7 +339,7 @@ public abstract class AbsTarget implements ITargetHand * 任务重试 */ @Override public void reTry() { - if (checkEntity()) { + if (checkConfig()) { List cmds = new ArrayList<>(); int taskType = checkTaskType(); cmds.add( @@ -319,7 +356,7 @@ public abstract class AbsTarget implements ITargetHand * {@code false}如果任务已经完成,只删除任务数据库记录, */ @Override public void cancel(boolean removeFile) { - if (checkEntity()) { + if (checkConfig()) { CancelCmd cancelCmd = (CancelCmd) CommonUtil.createNormalCmd(mTaskWrapper, NormalCmdFactory.TASK_CANCEL, checkTaskType()); @@ -332,9 +369,80 @@ public abstract class AbsTarget implements ITargetHand * 重新下载 */ @Override public void reStart() { - if (checkEntity()) { + if (checkConfig()) { cancel(); start(); } } + + private static class TempTask implements ITask { + + private AbsTaskWrapper wrapper; + private AbsEntity entity; + + private TempTask(AbsTaskWrapper wrapper, AbsEntity entity) { + this.wrapper = wrapper; + this.entity = entity; + } + + @Override public int getTaskType() { + return TEMP; + } + + @Override public int getState() { + return entity.getState(); + } + + @Override public String getKey() { + return entity.getKey(); + } + + @Override public boolean isRunning() { + return false; + } + + @Override public AbsTaskWrapper getTaskWrapper() { + return wrapper; + } + + @Override public void start() { + + } + + @Override public void stop() { + + } + + @Override public void stop(int type) { + + } + + @Override public void cancel() { + + } + + @Override public Object getExpand(String key) { + return null; + } + + @Override public boolean isStop() { + return false; + } + + @Override public boolean isCancel() { + return false; + } + + @Override public boolean isNeedRetry() { + return false; + } + + @Override public String getTaskName() { + return "TempTask"; + } + + @Override public int getSchedulerType() { + return TaskSchedulerType.TYPE_DEFAULT; + } + } } diff --git a/Aria/src/main/java/com/arialyy/aria/core/inf/AbsTask.java b/Aria/src/main/java/com/arialyy/aria/core/inf/AbsTask.java index 2ef76362..79c156dc 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/inf/AbsTask.java +++ b/Aria/src/main/java/com/arialyy/aria/core/inf/AbsTask.java @@ -32,9 +32,9 @@ public abstract class AbsTask * 才能生效 */ - @Override public long getSpeed() { + public long getSpeed() { return mTaskWrapper.getEntity().getSpeed(); } @@ -277,7 +289,7 @@ public abstract class AbsTask * 才能生效 */ - @Override public String getConvertSpeed() { + public String getConvertSpeed() { return mTaskWrapper.getEntity().getConvertSpeed(); } @@ -285,11 +297,6 @@ public abstract class AbsTask */ private boolean refreshInfo = false; - /** - * 任务状态,和Entity的state同步 - */ - private int state = IEntity.STATE_WAIT; - /** * 是否是新任务,{@code true} 新任务 */ @@ -142,7 +137,6 @@ public abstract class AbsTaskWrapper } public void setState(int state) { - this.state = state; entity.setState(state); } diff --git a/Aria/src/main/java/com/arialyy/aria/core/inf/IHttpHeaderDelegate.java b/Aria/src/main/java/com/arialyy/aria/core/inf/IHttpHeaderDelegate.java index fdc930ba..4f4a93d8 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/inf/IHttpHeaderDelegate.java +++ b/Aria/src/main/java/com/arialyy/aria/core/inf/IHttpHeaderDelegate.java @@ -1,50 +1,50 @@ -/* - * 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.inf; - -import android.support.annotation.CheckResult; -import android.support.annotation.NonNull; -import java.net.Proxy; -import java.util.Map; - -/** - * Created by laoyuyu on 2018/3/9. - * HTTP Header功能接口 - */ -public interface IHttpHeaderDelegate { - - /** - * 给url请求添加Header数据 - * 如果新的header数据和数据保存的不一致,则更新数据库中对应的header数据 - * - * @param key header对应的key - * @param value header对应的value - */ - @CheckResult - TARGET addHeader(@NonNull String key, @NonNull String value); - - /** - * 给url请求添加一组header数据 - * 如果新的header数据和数据保存的不一致,则更新数据库中对应的header数据 - * - * @param headers 一组http header数据 - */ - @CheckResult - TARGET addHeaders(Map headers); - - @CheckResult - TARGET setUrlProxy(Proxy proxy); -} +/* + * 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.inf; + +import android.support.annotation.CheckResult; +import android.support.annotation.NonNull; +import java.net.Proxy; +import java.util.Map; + +/** + * Created by laoyuyu on 2018/3/9. + * D_HTTP Header功能接口 + */ +public interface IHttpHeaderDelegate { + + /** + * 给url请求添加Header数据 + * 如果新的header数据和数据保存的不一致,则更新数据库中对应的header数据 + * + * @param key header对应的key + * @param value header对应的value + */ + @CheckResult + TARGET addHeader(@NonNull String key, @NonNull String value); + + /** + * 给url请求添加一组header数据 + * 如果新的header数据和数据保存的不一致,则更新数据库中对应的header数据 + * + * @param headers 一组http header数据 + */ + @CheckResult + TARGET addHeaders(Map headers); + + @CheckResult + TARGET setUrlProxy(Proxy proxy); +} diff --git a/Aria/src/main/java/com/arialyy/aria/core/inf/ITargetHandler.java b/Aria/src/main/java/com/arialyy/aria/core/inf/ITargetHandler.java index 0c2ae824..808db8cd 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/inf/ITargetHandler.java +++ b/Aria/src/main/java/com/arialyy/aria/core/inf/ITargetHandler.java @@ -1,77 +1,79 @@ -/* - * 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.inf; - -/** - * Created by AriaL on 2017/6/29. - * 任务接收器的控制接口,处理添加任务、开始任务、停止任务、删除任务等功能 - */ -public interface ITargetHandler { - int HTTP = 1; - int FTP = 2; - //HTTP任务组 - int GROUP_HTTP = 3; - //FTP文件夹 - int GROUP_FTP_DIR = 4; - - /** - * 添加任务 - */ - void add(); - - /** - * 开始下载 - */ - void start(); - - /** - * 停止下载 - */ - void stop(); - - /** - * 恢复下载 - */ - void resume(); - - /** - * 取消下载 - */ - void cancel(); - - /** - * 保存修改 - */ - void save(); - - /** - * 删除任务 - * - * @param removeFile {@code true} 不仅删除任务数据库记录,还会删除已经删除完成的文件 - * {@code false}如果任务已经完成,只删除任务数据库记录, - */ - void cancel(boolean removeFile); - - /** - * 任务重试 - */ - void reTry(); - - /** - * 重新下载 - */ - void reStart(); -} +/* + * 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.inf; + +/** + * Created by AriaL on 2017/6/29. + * 任务接收器的控制接口,处理添加任务、开始任务、停止任务、删除任务等功能 + */ +public interface ITargetHandler { + int D_HTTP = 1; + int U_HTTP = 2; + int U_FTP = 3; + int D_FTP = 4; + //HTTP任务组 + int GROUP_HTTP = 5; + //FTP文件夹 + int GROUP_FTP_DIR = 6; + + /** + * 添加任务 + */ + void add(); + + /** + * 开始下载 + */ + void start(); + + /** + * 停止下载 + */ + void stop(); + + /** + * 恢复下载 + */ + void resume(); + + /** + * 取消下载 + */ + void cancel(); + + /** + * 保存修改 + */ + void save(); + + /** + * 删除任务 + * + * @param removeFile {@code true} 不仅删除任务数据库记录,还会删除已经删除完成的文件 + * {@code false}如果任务已经完成,只删除任务数据库记录, + */ + void cancel(boolean removeFile); + + /** + * 任务重试 + */ + void reTry(); + + /** + * 重新下载 + */ + void reStart(); +} diff --git a/Aria/src/main/java/com/arialyy/aria/core/inf/ITask.java b/Aria/src/main/java/com/arialyy/aria/core/inf/ITask.java index 9540ec57..84b811b1 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/inf/ITask.java +++ b/Aria/src/main/java/com/arialyy/aria/core/inf/ITask.java @@ -1,133 +1,139 @@ -/* - * 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.inf; - -import com.arialyy.aria.core.download.DownloadGroupTask; -import com.arialyy.aria.core.download.DownloadTask; -import com.arialyy.aria.core.upload.UploadTask; - -/** - * Created by lyy on 2017/2/13. - * 任务接口{@link DownloadTask}、{@link UploadTask}、{@link DownloadGroupTask} - */ -public interface ITask { - - /** - * 普通下载任务 - */ - int DOWNLOAD = 1; - /** - * 上传任务 - */ - int UPLOAD = 2; - /** - * 组合任务 - */ - int DOWNLOAD_GROUP = 3; - /** - * 组合任务的子任务 - */ - int DOWNLOAD_GROUP_SUB = 4; - /** - * 未知 - */ - int OTHER = -1; - - /** - * 获取任务类型 - * - * @return {@link #DOWNLOAD}、{@link #UPLOAD}、{@link #DOWNLOAD_GROUP} - */ - int getTaskType(); - - /** - * 获取下载状态 - */ - int getState(); - - /** - * 唯一标识符,DownloadTask 为下载地址,UploadTask 为文件路径 - */ - String getKey(); - - /** - * 任务是否正在执行 - * - * @return true,正在执行; - */ - boolean isRunning(); - - /** - * 获取信息实体 - */ - TASK_WRAPPER getTaskWrapper(); - - void start(); - - /** - * 停止任务 - */ - void stop(); - - /** - * 停止任务 - * - * @param type {@code 0}默认操作,{@code 1}停止任务不自动执行下一任务 - */ - void stop(int type); - - /** - * 删除任务 - */ - void cancel(); - - /** - * 原始byte速度 - */ - long getSpeed(); - - /** - * 转换单位后的速度 - */ - String getConvertSpeed(); - - /** - * 获取百分比进度 - */ - int getPercent(); - - /** - * 原始文件byte长度 - */ - long getFileSize(); - - /** - * 转换单位后的文件长度 - */ - String getConvertFileSize(); - - /** - * 获取当前进度 - */ - long getCurrentProgress(); - - /** - * 获取单位转换后的进度 - * - * @return 返回 3mb - */ - String getConvertCurrentProgress(); -} +/* + * 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.inf; + +import com.arialyy.aria.core.download.DownloadGroupTask; +import com.arialyy.aria.core.download.DownloadTask; +import com.arialyy.aria.core.upload.UploadTask; + +/** + * Created by lyy on 2017/2/13. + * 任务接口{@link DownloadTask}、{@link UploadTask}、{@link DownloadGroupTask} + */ +public interface ITask { + + /** + * 普通下载任务 + */ + int DOWNLOAD = 1; + /** + * 上传任务 + */ + int UPLOAD = 2; + /** + * 组合任务 + */ + int DOWNLOAD_GROUP = 3; + /** + * 组合任务的子任务 + */ + int DOWNLOAD_GROUP_SUB = 4; + /** + * 填充的 + */ + int TEMP = 5; + /** + * 未知 + */ + int OTHER = -1; + + /** + * 获取任务类型 + * + * @return {@link #DOWNLOAD}、{@link #UPLOAD}、{@link #DOWNLOAD_GROUP} + */ + int getTaskType(); + + /** + * 获取下载状态 + */ + int getState(); + + /** + * 唯一标识符,DownloadTask 为下载地址,UploadTask 为文件路径 + */ + String getKey(); + + /** + * 任务是否正在执行 + * + * @return true,正在执行; + */ + boolean isRunning(); + + /** + * 获取信息实体 + */ + TASK_WRAPPER getTaskWrapper(); + + void start(); + + /** + * 停止任务 + */ + void stop(); + + /** + * 停止任务 + * + * @param type {@code 0}默认操作,{@code 1}停止任务不自动执行下一任务 + */ + void stop(int type); + + /** + * 删除任务 + */ + void cancel(); + + /** + * 读取扩展数据 + */ + Object getExpand(String key); + + /** + * 任务是否停止了 + * + * @return {@code true}任务已经停止 + */ + boolean isStop(); + + /** + * 任务是否取消了 + * + * @return {@code true}任务已经取消 + */ + boolean isCancel(); + + /** + * 任务是否需要重试 + * + * @return {@code true}任务已经取消 + */ + boolean isNeedRetry(); + + /** + * 获取任务名,也就是文件名 + */ + String getTaskName(); + + /** + * 任务的调度类型 + * {@link TaskSchedulerType} + */ + int getSchedulerType(); + + +} diff --git a/Aria/src/main/java/com/arialyy/aria/core/queue/ITaskQueue.java b/Aria/src/main/java/com/arialyy/aria/core/queue/ITaskQueue.java index bfa5f270..b669150b 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/queue/ITaskQueue.java +++ b/Aria/src/main/java/com/arialyy/aria/core/queue/ITaskQueue.java @@ -22,13 +22,14 @@ import com.arialyy.aria.core.download.DownloadTask; import com.arialyy.aria.core.download.DTaskWrapper; import com.arialyy.aria.core.inf.AbsTask; import com.arialyy.aria.core.inf.AbsTaskWrapper; +import com.arialyy.aria.core.inf.ITask; import com.arialyy.aria.core.upload.UploadTask; import com.arialyy.aria.core.upload.UTaskWrapper; /** * Created by lyy on 2016/8/16. 任务功能接口 */ -public interface ITaskQueue { +public interface ITaskQueue { /** * 通过key跑断任务是在存在 diff --git a/Aria/src/main/java/com/arialyy/aria/core/scheduler/AbsSchedulers.java b/Aria/src/main/java/com/arialyy/aria/core/scheduler/AbsSchedulers.java index 07ccf423..8c51e4c6 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/scheduler/AbsSchedulers.java +++ b/Aria/src/main/java/com/arialyy/aria/core/scheduler/AbsSchedulers.java @@ -45,7 +45,7 @@ import java.util.concurrent.TimeUnit; /** * Created by lyy on 2017/6/4. 事件调度器,用于处理任务状态的调度 */ -abstract class AbsSchedulers> implements ISchedulers { private final String TAG = "AbsSchedulers"; @@ -273,7 +273,8 @@ abstract class AbsSchedulers - implements IFtpTarget { - private FtpDelegate mFtpDelegate; - private UNormalDelegate mNormalDelegate; - - FtpUploadTarget(String filePath, String targetName) { - mNormalDelegate = new UNormalDelegate<>(this, filePath, targetName); - initTask(); - } - - private void initTask() { - getTaskWrapper().setRequestType(AbsTaskWrapper.U_FTP); - mFtpDelegate = new FtpDelegate<>(this); - } - - /** - * 设置上传路径 - * - * @param tempUrl 上传路径 - */ - public FtpUploadTarget setUploadUrl(String tempUrl) { - mNormalDelegate.setTempUrl(tempUrl); - return this; - } - - /** - * 是否是FTPS协议 - * 如果是FTPS协议,需要使用{@link FTPSDelegate#setStorePath(String)} 、{@link FTPSDelegate#setAlias(String)} - * 设置证书信息 - */ - @CheckResult - public FTPSDelegate asFtps() { - if (getTaskWrapper().asFtp().getUrlEntity() == null) { - FtpUrlEntity urlEntity = new FtpUrlEntity(); - urlEntity.isFtps = true; - getTaskWrapper().asFtp().setUrlEntity(urlEntity); - } - return new FTPSDelegate<>(this); - } - - @CheckResult - @Override public FtpUploadTarget charSet(String charSet) { - return mFtpDelegate.charSet(charSet); - } - - @Override public FtpUploadTarget login(String userName, String password) { - return mFtpDelegate.login(userName, password); - } - - @Override public FtpUploadTarget login(String userName, String password, String account) { - CheckUtil.checkFtpUploadUrl(mNormalDelegate.getTempUrl()); - return mFtpDelegate.login(userName, password, account); - } - - @Override public FtpUploadTarget setProxy(Proxy proxy) { - return mFtpDelegate.setProxy(proxy); - } - - @Override protected boolean checkEntity() { - return mNormalDelegate.checkEntity(); - } - - @Override public boolean isRunning() { - return mNormalDelegate.isRunning(); - } - - @Override public boolean taskExists() { - return mNormalDelegate.taskExists(); - } - - @Override public int getTargetType() { - return FTP; - } -} +/* + * 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.upload; + +import android.support.annotation.CheckResult; +import com.arialyy.aria.core.FtpUrlEntity; +import com.arialyy.aria.core.common.ftp.FTPSDelegate; +import com.arialyy.aria.core.common.ftp.FtpDelegate; +import com.arialyy.aria.core.inf.AbsTaskWrapper; +import com.arialyy.aria.core.inf.IFtpTarget; +import com.arialyy.aria.util.CheckUtil; +import java.net.Proxy; + +/** + * Created by Aria.Lao on 2017/7/27. + * ftp单任务上传 + */ +public class FtpUploadTarget extends AbsUploadTarget + implements IFtpTarget { + private FtpDelegate mFtpDelegate; + private UNormalDelegate mNormalDelegate; + + FtpUploadTarget(String filePath, String targetName) { + mNormalDelegate = new UNormalDelegate<>(this, filePath, targetName); + initTask(); + } + + private void initTask() { + getTaskWrapper().setRequestType(AbsTaskWrapper.U_FTP); + mFtpDelegate = new FtpDelegate<>(this); + } + + /** + * 设置上传路径 + * + * @param tempUrl 上传路径 + */ + public FtpUploadTarget setUploadUrl(String tempUrl) { + mNormalDelegate.setTempUrl(tempUrl); + return this; + } + + /** + * 是否是FTPS协议 + * 如果是FTPS协议,需要使用{@link FTPSDelegate#setStorePath(String)} 、{@link FTPSDelegate#setAlias(String)} + * 设置证书信息 + */ + @CheckResult + public FTPSDelegate asFtps() { + if (getTaskWrapper().asFtp().getUrlEntity() == null) { + FtpUrlEntity urlEntity = new FtpUrlEntity(); + urlEntity.isFtps = true; + getTaskWrapper().asFtp().setUrlEntity(urlEntity); + } + return new FTPSDelegate<>(this); + } + + @CheckResult + @Override public FtpUploadTarget charSet(String charSet) { + return mFtpDelegate.charSet(charSet); + } + + @Override public FtpUploadTarget login(String userName, String password) { + return mFtpDelegate.login(userName, password); + } + + @Override public FtpUploadTarget login(String userName, String password, String account) { + CheckUtil.checkFtpUploadUrl(mNormalDelegate.getTempUrl()); + return mFtpDelegate.login(userName, password, account); + } + + @Override public FtpUploadTarget setProxy(Proxy proxy) { + return mFtpDelegate.setProxy(proxy); + } + + @Override protected boolean checkEntity() { + return mNormalDelegate.checkEntity(); + } + + @Override public boolean isRunning() { + return mNormalDelegate.isRunning(); + } + + @Override public boolean taskExists() { + return mNormalDelegate.taskExists(); + } + + @Override public int getTargetType() { + return U_FTP; + } +} diff --git a/Aria/src/main/java/com/arialyy/aria/core/upload/UNormalDelegate.java b/Aria/src/main/java/com/arialyy/aria/core/upload/UNormalDelegate.java index f0d98079..8f7ecc58 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/upload/UNormalDelegate.java +++ b/Aria/src/main/java/com/arialyy/aria/core/upload/UNormalDelegate.java @@ -22,6 +22,7 @@ import com.arialyy.aria.core.manager.TaskWrapperManager; import com.arialyy.aria.core.queue.UploadTaskQueue; import com.arialyy.aria.orm.DbEntity; import com.arialyy.aria.util.ALog; +import com.arialyy.aria.util.CheckUtil; import com.arialyy.aria.util.CommonUtil; import java.io.File; @@ -121,7 +122,7 @@ class UNormalDelegate implements INormalTarget { if (TextUtils.isEmpty(url)) { ALog.e(TAG, "上传失败,url为null"); return false; - } else if (!url.startsWith("http") && !url.startsWith("ftp")) { + } else if (!CheckUtil.checkUrlNotThrow(url)) { ALog.e(TAG, "上传失败,url【" + url + "】错误"); return false; } 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 542536fd..58d5af1c 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 @@ -1,125 +1,125 @@ -/* - * 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.upload; - -import android.support.annotation.CheckResult; -import android.support.annotation.NonNull; -import com.arialyy.aria.core.common.http.HttpHeaderDelegate; -import com.arialyy.aria.core.common.http.PostDelegate; -import com.arialyy.aria.core.inf.AbsTaskWrapper; -import com.arialyy.aria.core.inf.IHttpHeaderDelegate; -import java.net.Proxy; -import java.util.Map; - -/** - * Created by lyy on 2017/2/28. - * http 单文件上传 - */ -public class UploadTarget extends AbsUploadTarget - implements IHttpHeaderDelegate { - private HttpHeaderDelegate mHeaderDelegate; - private UNormalDelegate mNormalDelegate; - - UploadTarget(String filePath, String targetName) { - mNormalDelegate = new UNormalDelegate<>(this, filePath, targetName); - initTask(); - } - - private void initTask() { - //http暂时不支持断点上传 - getTaskWrapper().setSupportBP(false); - getTaskWrapper().setRequestType(AbsTaskWrapper.U_HTTP); - mHeaderDelegate = new HttpHeaderDelegate<>(this); - } - - /** - * 设置上传路径 - * - * @param tempUrl 上传路径 - */ - public UploadTarget setUploadUrl(String tempUrl) { - mNormalDelegate.setTempUrl(tempUrl); - return this; - } - - /** - * Post处理 - */ - public PostDelegate asPost() { - return new PostDelegate<>(this); - } - - /** - * 设置userAgent - */ - @CheckResult - public UploadTarget setUserAngent(@NonNull String userAgent) { - getTaskWrapper().asHttp().setUserAgent(userAgent); - return this; - } - - /** - * 设置服务器需要的附件key - * - * @param attachment 附件key - */ - @CheckResult - public UploadTarget setAttachment(@NonNull String attachment) { - getTaskWrapper().asHttp().setAttachment(attachment); - return this; - } - - /** - * 设置上传文件类型 - * - * @param contentType tip:multipart/form-data - */ - @CheckResult - public UploadTarget setContentType(String contentType) { - getTaskWrapper().asHttp().setContentType(contentType); - return this; - } - - @CheckResult - @Override public UploadTarget addHeader(@NonNull String key, @NonNull String value) { - return mHeaderDelegate.addHeader(key, value); - } - - @CheckResult - @Override public UploadTarget addHeaders(Map headers) { - return mHeaderDelegate.addHeaders(headers); - } - - @Override public UploadTarget setUrlProxy(Proxy proxy) { - return mHeaderDelegate.setUrlProxy(proxy); - } - - @Override protected boolean checkEntity() { - return mNormalDelegate.checkEntity(); - } - - @Override public boolean isRunning() { - return mNormalDelegate.isRunning(); - } - - @Override public boolean taskExists() { - return mNormalDelegate.taskExists(); - } - - @Override public int getTargetType() { - return HTTP; - } -} +/* + * 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.upload; + +import android.support.annotation.CheckResult; +import android.support.annotation.NonNull; +import com.arialyy.aria.core.common.http.HttpHeaderDelegate; +import com.arialyy.aria.core.common.http.PostDelegate; +import com.arialyy.aria.core.inf.AbsTaskWrapper; +import com.arialyy.aria.core.inf.IHttpHeaderDelegate; +import java.net.Proxy; +import java.util.Map; + +/** + * Created by lyy on 2017/2/28. + * http 单文件上传 + */ +public class UploadTarget extends AbsUploadTarget + implements IHttpHeaderDelegate { + private HttpHeaderDelegate mHeaderDelegate; + private UNormalDelegate mNormalDelegate; + + UploadTarget(String filePath, String targetName) { + mNormalDelegate = new UNormalDelegate<>(this, filePath, targetName); + initTask(); + } + + private void initTask() { + //http暂时不支持断点上传 + getTaskWrapper().setSupportBP(false); + getTaskWrapper().setRequestType(AbsTaskWrapper.U_HTTP); + mHeaderDelegate = new HttpHeaderDelegate<>(this); + } + + /** + * 设置上传路径 + * + * @param tempUrl 上传路径 + */ + public UploadTarget setUploadUrl(String tempUrl) { + mNormalDelegate.setTempUrl(tempUrl); + return this; + } + + /** + * Post处理 + */ + public PostDelegate asPost() { + return new PostDelegate<>(this); + } + + /** + * 设置userAgent + */ + @CheckResult + public UploadTarget setUserAngent(@NonNull String userAgent) { + getTaskWrapper().asHttp().setUserAgent(userAgent); + return this; + } + + /** + * 设置服务器需要的附件key + * + * @param attachment 附件key + */ + @CheckResult + public UploadTarget setAttachment(@NonNull String attachment) { + getTaskWrapper().asHttp().setAttachment(attachment); + return this; + } + + /** + * 设置上传文件类型 + * + * @param contentType tip:multipart/form-data + */ + @CheckResult + public UploadTarget setContentType(String contentType) { + getTaskWrapper().asHttp().setContentType(contentType); + return this; + } + + @CheckResult + @Override public UploadTarget addHeader(@NonNull String key, @NonNull String value) { + return mHeaderDelegate.addHeader(key, value); + } + + @CheckResult + @Override public UploadTarget addHeaders(Map headers) { + return mHeaderDelegate.addHeaders(headers); + } + + @Override public UploadTarget setUrlProxy(Proxy proxy) { + return mHeaderDelegate.setUrlProxy(proxy); + } + + @Override protected boolean checkEntity() { + return mNormalDelegate.checkEntity(); + } + + @Override public boolean isRunning() { + return mNormalDelegate.isRunning(); + } + + @Override public boolean taskExists() { + return mNormalDelegate.taskExists(); + } + + @Override public int getTargetType() { + return U_HTTP; + } +} diff --git a/Aria/src/main/java/com/arialyy/aria/core/upload/uploader/FtpThreadTask.java b/Aria/src/main/java/com/arialyy/aria/core/upload/uploader/FtpThreadTask.java index b1e86c53..62a16fdb 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/upload/uploader/FtpThreadTask.java +++ b/Aria/src/main/java/com/arialyy/aria/core/upload/uploader/FtpThreadTask.java @@ -35,7 +35,7 @@ import java.io.IOException; import java.io.UnsupportedEncodingException; /** - * Created by Aria.Lao on 2017/7/28. FTP 单线程上传任务,需要FTP 服务器给用户打开append和write的权限 + * Created by Aria.Lao on 2017/7/28. D_FTP 单线程上传任务,需要FTP 服务器给用户打开append和write的权限 */ class FtpThreadTask extends AbsFtpThreadTask { private final String TAG = "FtpThreadTask"; diff --git a/Aria/src/main/java/com/arialyy/aria/util/CheckUtil.java b/Aria/src/main/java/com/arialyy/aria/util/CheckUtil.java index e35449a0..8891a0a5 100644 --- a/Aria/src/main/java/com/arialyy/aria/util/CheckUtil.java +++ b/Aria/src/main/java/com/arialyy/aria/util/CheckUtil.java @@ -118,7 +118,7 @@ public class CheckUtil { public static void checkUrlInvalidThrow(String url) { if (TextUtils.isEmpty(url)) { throw new IllegalArgumentException("url不能为null"); - } else if (!url.startsWith("http") && !url.startsWith("ftp")) { + } else if (!url.startsWith("http") && !url.startsWith("ftp") && !url.startsWith("sftp")) { throw new IllegalArgumentException("url错误"); } int index = url.indexOf("://"); @@ -133,7 +133,7 @@ public class CheckUtil { public static void checkUrl(String url) { if (TextUtils.isEmpty(url)) { throw new NullPointerException("url为空"); - } else if (!url.startsWith("http") && !url.startsWith("ftp")) { + } else if (!url.startsWith("http") && !url.startsWith("ftp") && !url.startsWith("sftp")) { throw new IllegalArgumentException(String.format("url【%s】错误", url)); } int index = url.indexOf("://"); @@ -151,7 +151,7 @@ public class CheckUtil { if (TextUtils.isEmpty(url)) { ALog.e(TAG, "url不能为null"); return false; - } else if (!url.startsWith("http") && !url.startsWith("ftp")) { + } else if (!url.startsWith("http") && !url.startsWith("ftp") && !url.startsWith("sftp")) { ALog.e(TAG, "url【" + url + "】错误"); return false; } diff --git a/DEV_LOG.md b/DEV_LOG.md index 82924c79..08b35bd5 100644 --- a/DEV_LOG.md +++ b/DEV_LOG.md @@ -1,5 +1,5 @@ ## 开发日志 - + v_3.6.4 + + v_3.6.4 (2019/5/16) - 优化任务接收器的代码结构 - 修复`DbEntity.saveAll()`失败的问题 - 修复分块任务重命名失败的问题 @@ -10,7 +10,7 @@ - fix bug https://github.com/AriaLyy/Aria/issues/388 - 修复使用`Content-Disposition`的文件名时,第一次下载无法重命名文件的问题 - 修复使用`Content-Disposition`的文件名时,多次重命名文件的问题 - - 组合任务新增`unknownSize()`,用于处理组合任务大小未知的情况,https://github.com/AriaLyy/Aria/issues/380 + - 组合任务新增`unknownSize()`,用于处理组合任务大小ø未知的情况,https://github.com/AriaLyy/Aria/issues/380 - 优化`AbsThreadTask`代码 - 新增文件长度处理功能 https://github.com/AriaLyy/Aria/issues/393 ```java @@ -27,6 +27,8 @@ - 优化`isRunning()`的逻辑,任务是否在执行的判断将更加准确 - 修复多次重复快速点击`暂停、开始`时,任务有可能重复下载的问题 - 修复组合任务中没有等待中的只任务实体保存失败的问题 + - 新增组合任务url重复检查 https://github.com/AriaLyy/Aria/issues/395 + - 初始化任务时,如果url、path有错误将会回调`@Download.onTaskFail`、`@Upload.onTaskFail`、`@DownGroup.onTaskFail` + v_3.6.3 (2019/4/2) - fix bug https://github.com/AriaLyy/Aria/issues/377 + v_3.6.2 (2019/4/1) diff --git a/README.md b/README.md index 2d4a24d0..da6ed806 100644 --- a/README.md +++ b/README.md @@ -42,8 +42,8 @@ Aria有以下特点: [![Compiler](https://api.bintray.com/packages/arialyy/maven/AriaCompiler/images/download.svg)](https://bintray.com/arialyy/maven/AriaCompiler/_latestVersion) ```java -compile 'com.arialyy.aria:aria-core:3.6.3' -annotationProcessor 'com.arialyy.aria:aria-compiler:3.6.3' +compile 'com.arialyy.aria:aria-core:3.6.4' +annotationProcessor 'com.arialyy.aria:aria-compiler:3.6.4' ``` 如果出现android support依赖错误,请将 `compile 'com.arialyy.aria:aria-core:'`替换为 ``` @@ -113,12 +113,36 @@ protected void onCreate(Bundle savedInstanceState) { ### 版本日志 -* v3.6.3 (2019/4/2) - - fix bug https://github.com/AriaLyy/Aria/issues/368 - - 增加gradle 5.0支持 - - fix bug https://github.com/AriaLyy/Aria/issues/374 - - fix bug https://github.com/AriaLyy/Aria/issues/377 - - 增加分页获取任务列表api, 详情见:https://aria.laoyuyu.me/aria_doc/api/task_list.html#%E4%BB%BB%E5%8A%A1%E5%88%97%E8%A1%A8%E5%88%86%E9%A1%B5%EF%BC%88362%E4%BB%A5%E4%B8%8A%E7%89%88%E6%9C%AC%E6%94%AF%E6%8C%81%EF%BC%89 + + v_3.6.4 (2019/5/16) + - 优化任务接收器的代码结构 + - 修复`DbEntity.saveAll()`失败的问题 + - 修复分块任务重命名失败的问题 + - fix bug https://github.com/AriaLyy/Aria/issues/379 + - 移除`getDownloadTask(String url)`、`getGroupTask(List urls)`、`getFtpDirTask(String path)` + 等获取任务的api,如果你希望获取对应状态,请使用实体的状态判断,如:`getDownloadEntity()`、`getDownloadGroupEntity()` + `getFtpDirEntity()` + - fix bug https://github.com/AriaLyy/Aria/issues/388 + - 修复使用`Content-Disposition`的文件名时,第一次下载无法重命名文件的问题 + - 修复使用`Content-Disposition`的文件名时,多次重命名文件的问题 + - 组合任务新增`unknownSize()`,用于处理组合任务大小ø未知的情况,https://github.com/AriaLyy/Aria/issues/380 + - 优化`AbsThreadTask`代码 + - 新增文件长度处理功能 https://github.com/AriaLyy/Aria/issues/393 + ```java + .setFileLenAdapter(new IHttpFileLenAdapter() { + @Override public long handleFileLen(Map> headers) { + ... + // 处理header中的文件长度 + + return fileLen; + } + }) + ``` + - 修复组合任务多次回调`onStop`注解的问题 + - 优化`isRunning()`的逻辑,任务是否在执行的判断将更加准确 + - 修复多次重复快速点击`暂停、开始`时,任务有可能重复下载的问题 + - 修复组合任务中没有等待中的只任务实体保存失败的问题 + - 新增组合任务url重复检查 https://github.com/AriaLyy/Aria/issues/395 + - 初始化任务时,如果url、path有错误将会回调`@Download.onTaskFail`、`@Upload.onTaskFail`、`@DownGroup.onTaskFail` [更多版本记录](https://github.com/AriaLyy/Aria/blob/master/DEV_LOG.md) diff --git a/app/src/main/java/com/arialyy/simple/base/BaseApplication.java b/app/src/main/java/com/arialyy/simple/base/BaseApplication.java index 6b094c01..3dcd7f94 100644 --- a/app/src/main/java/com/arialyy/simple/base/BaseApplication.java +++ b/app/src/main/java/com/arialyy/simple/base/BaseApplication.java @@ -24,7 +24,7 @@ import com.arialyy.aria.core.Aria; import com.arialyy.frame.core.AbsFrame; import com.arialyy.simple.BuildConfig; import com.arialyy.simple.common.ConnectionChangeReceiver; -import com.squareup.leakcanary.LeakCanary; +//import com.squareup.leakcanary.LeakCanary; /** * Created by Lyy on 2016/9/27. @@ -45,18 +45,15 @@ public class BaseApplication extends Application { .build()); StrictMode.setThreadPolicy( new StrictMode.ThreadPolicy.Builder().detectAll().penaltyLog().build()); - if (LeakCanary.isInAnalyzerProcess(this)) {//1 + //if (LeakCanary.isInAnalyzerProcess(this)) {//1 // This process is dedicated to LeakCanary for heap analysis. // You should not init your app in this process. - return; - } - LeakCanary.install(this); + //return; + //} + //LeakCanary.install(this); } - registerReceiver(new ConnectionChangeReceiver(), - new - - IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION)); + //registerReceiver(new ConnectionChangeReceiver(), new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION)); } public static BaseApplication getApp() { diff --git a/app/src/main/java/com/arialyy/simple/core/download/FtpDownloadActivity.java b/app/src/main/java/com/arialyy/simple/core/download/FtpDownloadActivity.java index 8130ec4c..6c1a3804 100644 --- a/app/src/main/java/com/arialyy/simple/core/download/FtpDownloadActivity.java +++ b/app/src/main/java/com/arialyy/simple/core/download/FtpDownloadActivity.java @@ -35,7 +35,7 @@ import java.io.File; * Ftp下载测试 */ public class FtpDownloadActivity extends BaseActivity { - private final String URL = "ftp://9.9.9.205:2121/Cyberduck-6.9.4.30164.zip"; + private final String URL = "sftp://9.9.9.205:2222/Cyberduck-6.9.4.30164.zip"; //private final String URL = "ftp://182.92.180.213:21/video/572fed5c2ad48_1024.jpg"; //private final String URL = "ftp://182.92.180.213:21/DATA/20180205/rar/1111.rar"; //private final String URL = "ftp://d:d@dygodj8.com:12311/咖啡风暴HD大陆公映意语中字[飘花www.piaohua.com].mp4"; @@ -60,8 +60,9 @@ public class FtpDownloadActivity extends BaseActivity { //.addHeader("Cookie", "BAIDUID=648E5FF020CC69E8DD6F492D1068AAA9:FG=1; BIDUPSID=648E5FF020CC69E8DD6F492D1068AAA9; PSTM=1519099573; BD_UPN=12314753; locale=zh; BDSVRTM=0") .useServerFileName(true) .setFilePath(path, true) - .setFileLenAdapter(new AbsHttpFileLenAdapter() { + .setFileLenAdapter(new IHttpFileLenAdapter() { @Override public long handleFileLen(Map> headers) { List sLength = headers.get("Content-Length"); diff --git a/build.gradle b/build.gradle index a185b18d..a989f0ad 100644 --- a/build.gradle +++ b/build.gradle @@ -43,7 +43,7 @@ task clean(type: Delete) { ext { userOrg = 'arialyy' groupId = 'com.arialyy.aria' - publishVersion = '3.6.4_dev_2' + publishVersion = '3.6.4' // publishVersion = '1.0.4' //FTP插件 repoName='maven' desc = 'android 下载框架'