新增组合任务url重复检查 https://github.com/AriaLyy/Aria/issues/395
初始化任务时,如果url、path有错误将会回调`@Download.onTaskFail`、`@Upload.onTaskFail`、`@DownGroup.onTaskFail`v3.6.6 3.6.4
parent
9212aabd95
commit
15978cd2b6
@ -1,124 +1,124 @@ |
||||
/* |
||||
* 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; |
||||
|
||||
/** |
||||
* FTP SSL/TSL 参数委托 |
||||
*/ |
||||
public class FTPSDelegate<TARGET extends AbsTarget> 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<TARGET extends AbsTarget> 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(); |
||||
} |
||||
} |
||||
|
@ -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<TARGET extends AbsDTarget> extends AbsTarget<TARGET> { |
||||
|
||||
/** |
||||
* 更新下载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<TARGET extends AbsDTarget> extends AbsTarget<TARGET> { |
||||
|
||||
/** |
||||
* 更新下载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(); |
||||
} |
||||
} |
||||
|
@ -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<FtpDownloadTarget> |
||||
implements IFtpTarget<FtpDownloadTarget> { |
||||
private FtpDelegate<FtpDownloadTarget> mFtpDelegate; |
||||
private DNormalDelegate<FtpDownloadTarget> 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<FtpDownloadTarget> 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<FtpDownloadTarget> |
||||
implements IFtpTarget<FtpDownloadTarget> { |
||||
private FtpDelegate<FtpDownloadTarget> mFtpDelegate; |
||||
private DNormalDelegate<FtpDownloadTarget> 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<FtpDownloadTarget> 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); |
||||
} |
||||
} |
||||
|
@ -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<TARGET extends ITargetHandler> { |
||||
|
||||
/** |
||||
* 给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<String, String> 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<TARGET extends ITargetHandler> { |
||||
|
||||
/** |
||||
* 给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<String, String> headers); |
||||
|
||||
@CheckResult |
||||
TARGET setUrlProxy(Proxy proxy); |
||||
} |
||||
|
@ -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(); |
||||
} |
||||
|
@ -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<TASK_WRAPPER extends AbsTaskWrapper> { |
||||
|
||||
/** |
||||
* 普通下载任务 |
||||
*/ |
||||
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<TASK_WRAPPER extends AbsTaskWrapper> { |
||||
|
||||
/** |
||||
* 普通下载任务 |
||||
*/ |
||||
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(); |
||||
|
||||
|
||||
} |
||||
|
@ -1,104 +1,104 @@ |
||||
/* |
||||
* 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<FtpUploadTarget> |
||||
implements IFtpTarget<FtpUploadTarget> { |
||||
private FtpDelegate<FtpUploadTarget> mFtpDelegate; |
||||
private UNormalDelegate<FtpUploadTarget> 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<FtpUploadTarget> 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<FtpUploadTarget> |
||||
implements IFtpTarget<FtpUploadTarget> { |
||||
private FtpDelegate<FtpUploadTarget> mFtpDelegate; |
||||
private UNormalDelegate<FtpUploadTarget> 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<FtpUploadTarget> 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; |
||||
} |
||||
} |
||||
|
@ -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<UploadTarget> |
||||
implements IHttpHeaderDelegate<UploadTarget> { |
||||
private HttpHeaderDelegate<UploadTarget> mHeaderDelegate; |
||||
private UNormalDelegate<UploadTarget> 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<String, String> 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<UploadTarget> |
||||
implements IHttpHeaderDelegate<UploadTarget> { |
||||
private HttpHeaderDelegate<UploadTarget> mHeaderDelegate; |
||||
private UNormalDelegate<UploadTarget> 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<String, String> 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; |
||||
} |
||||
} |
||||
|
Loading…
Reference in new issue