新增组合任务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)
|
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
|
||||||
* |
* |
||||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||||
* you may not use this file except in compliance with the License. |
* you may not use this file except in compliance with the License. |
||||||
* You may obtain a copy of the License at |
* You may obtain a copy of the License at |
||||||
* |
* |
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
* |
* |
||||||
* Unless required by applicable law or agreed to in writing, software |
* Unless required by applicable law or agreed to in writing, software |
||||||
* distributed under the License is distributed on an "AS IS" BASIS, |
* distributed under the License is distributed on an "AS IS" BASIS, |
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||||
* See the License for the specific language governing permissions and |
* See the License for the specific language governing permissions and |
||||||
* limitations under the License. |
* limitations under the License. |
||||||
*/ |
*/ |
||||||
package com.arialyy.aria.core.common.ftp; |
package com.arialyy.aria.core.common.ftp; |
||||||
|
|
||||||
import android.text.TextUtils; |
import android.text.TextUtils; |
||||||
import com.arialyy.aria.core.FtpUrlEntity; |
import com.arialyy.aria.core.FtpUrlEntity; |
||||||
import com.arialyy.aria.core.common.ProtocolType; |
import com.arialyy.aria.core.common.ProtocolType; |
||||||
import com.arialyy.aria.core.inf.AbsTarget; |
import com.arialyy.aria.core.inf.AbsTarget; |
||||||
import com.arialyy.aria.core.inf.ITargetHandler; |
import com.arialyy.aria.core.inf.ITargetHandler; |
||||||
|
|
||||||
/** |
/** |
||||||
* FTP SSL/TSL 参数委托 |
* D_FTP SSL/TSL 参数委托 |
||||||
*/ |
*/ |
||||||
public class FTPSDelegate<TARGET extends AbsTarget> implements ITargetHandler { |
public class FTPSDelegate<TARGET extends AbsTarget> implements ITargetHandler { |
||||||
private final String TAG = "FTPSDelegate"; |
private final String TAG = "FTPSDelegate"; |
||||||
private TARGET mTarget; |
private TARGET mTarget; |
||||||
private FtpUrlEntity mUrlEntity; |
private FtpUrlEntity mUrlEntity; |
||||||
|
|
||||||
public FTPSDelegate(TARGET target) { |
public FTPSDelegate(TARGET target) { |
||||||
mTarget = target; |
mTarget = target; |
||||||
mUrlEntity = mTarget.getTaskWrapper().asFtp().getUrlEntity(); |
mUrlEntity = mTarget.getTaskWrapper().asFtp().getUrlEntity(); |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
* 设置协议类型 |
* 设置协议类型 |
||||||
* |
* |
||||||
* @param protocol {@link ProtocolType} |
* @param protocol {@link ProtocolType} |
||||||
*/ |
*/ |
||||||
public FTPSDelegate setProtocol(@ProtocolType String protocol) { |
public FTPSDelegate setProtocol(@ProtocolType String protocol) { |
||||||
if (TextUtils.isEmpty(protocol)) { |
if (TextUtils.isEmpty(protocol)) { |
||||||
throw new NullPointerException("协议为空"); |
throw new NullPointerException("协议为空"); |
||||||
} |
} |
||||||
mUrlEntity.protocol = protocol; |
mUrlEntity.protocol = protocol; |
||||||
return this; |
return this; |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
* 设置证书别名 |
* 设置证书别名 |
||||||
* |
* |
||||||
* @param keyAlias 别名 |
* @param keyAlias 别名 |
||||||
*/ |
*/ |
||||||
public FTPSDelegate setAlias(String keyAlias) { |
public FTPSDelegate setAlias(String keyAlias) { |
||||||
if (TextUtils.isEmpty(keyAlias)) { |
if (TextUtils.isEmpty(keyAlias)) { |
||||||
throw new NullPointerException("别名为空"); |
throw new NullPointerException("别名为空"); |
||||||
} |
} |
||||||
mUrlEntity.keyAlias = keyAlias; |
mUrlEntity.keyAlias = keyAlias; |
||||||
return this; |
return this; |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
* 设置证书密码 |
* 设置证书密码 |
||||||
* |
* |
||||||
* @param storePass 私钥密码 |
* @param storePass 私钥密码 |
||||||
*/ |
*/ |
||||||
public FTPSDelegate setStorePass(String storePass) { |
public FTPSDelegate setStorePass(String storePass) { |
||||||
if (TextUtils.isEmpty(storePass)) { |
if (TextUtils.isEmpty(storePass)) { |
||||||
throw new NullPointerException("证书密码为空"); |
throw new NullPointerException("证书密码为空"); |
||||||
} |
} |
||||||
mUrlEntity.storePass = storePass; |
mUrlEntity.storePass = storePass; |
||||||
return this; |
return this; |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
* 设置证书路径 |
* 设置证书路径 |
||||||
* |
* |
||||||
* @param storePath 证书路径 |
* @param storePath 证书路径 |
||||||
*/ |
*/ |
||||||
public FTPSDelegate setStorePath(String storePath) { |
public FTPSDelegate setStorePath(String storePath) { |
||||||
if (TextUtils.isEmpty(storePath)) { |
if (TextUtils.isEmpty(storePath)) { |
||||||
throw new NullPointerException("证书路径为空"); |
throw new NullPointerException("证书路径为空"); |
||||||
} |
} |
||||||
mUrlEntity.storePath = storePath; |
mUrlEntity.storePath = storePath; |
||||||
return this; |
return this; |
||||||
} |
} |
||||||
|
|
||||||
@Override public void add() { |
@Override public void add() { |
||||||
mTarget.add(); |
mTarget.add(); |
||||||
} |
} |
||||||
|
|
||||||
@Override public void start() { |
@Override public void start() { |
||||||
mTarget.start(); |
mTarget.start(); |
||||||
} |
} |
||||||
|
|
||||||
@Override public void stop() { |
@Override public void stop() { |
||||||
mTarget.stop(); |
mTarget.stop(); |
||||||
} |
} |
||||||
|
|
||||||
@Override public void resume() { |
@Override public void resume() { |
||||||
mTarget.resume(); |
mTarget.resume(); |
||||||
} |
} |
||||||
|
|
||||||
@Override public void cancel() { |
@Override public void cancel() { |
||||||
mTarget.cancel(); |
mTarget.cancel(); |
||||||
} |
} |
||||||
|
|
||||||
@Override public void save() { |
@Override public void save() { |
||||||
mTarget.save(); |
mTarget.save(); |
||||||
} |
} |
||||||
|
|
||||||
@Override public void cancel(boolean removeFile) { |
@Override public void cancel(boolean removeFile) { |
||||||
mTarget.cancel(removeFile); |
mTarget.cancel(removeFile); |
||||||
} |
} |
||||||
|
|
||||||
@Override public void reTry() { |
@Override public void reTry() { |
||||||
mTarget.reTry(); |
mTarget.reTry(); |
||||||
} |
} |
||||||
|
|
||||||
@Override public void reStart() { |
@Override public void reStart() { |
||||||
mTarget.reStart(); |
mTarget.reStart(); |
||||||
} |
} |
||||||
} |
} |
||||||
|
@ -1,57 +1,57 @@ |
|||||||
/* |
/* |
||||||
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
|
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
|
||||||
* |
* |
||||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||||
* you may not use this file except in compliance with the License. |
* you may not use this file except in compliance with the License. |
||||||
* You may obtain a copy of the License at |
* You may obtain a copy of the License at |
||||||
* |
* |
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
* |
* |
||||||
* Unless required by applicable law or agreed to in writing, software |
* Unless required by applicable law or agreed to in writing, software |
||||||
* distributed under the License is distributed on an "AS IS" BASIS, |
* distributed under the License is distributed on an "AS IS" BASIS, |
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||||
* See the License for the specific language governing permissions and |
* See the License for the specific language governing permissions and |
||||||
* limitations under the License. |
* limitations under the License. |
||||||
*/ |
*/ |
||||||
package com.arialyy.aria.core.download; |
package com.arialyy.aria.core.download; |
||||||
|
|
||||||
import com.arialyy.aria.core.AriaManager; |
import com.arialyy.aria.core.AriaManager; |
||||||
import com.arialyy.aria.core.command.normal.NormalCmdFactory; |
import com.arialyy.aria.core.command.normal.NormalCmdFactory; |
||||||
import com.arialyy.aria.core.inf.AbsTarget; |
import com.arialyy.aria.core.inf.AbsTarget; |
||||||
import com.arialyy.aria.util.CommonUtil; |
import com.arialyy.aria.util.CommonUtil; |
||||||
|
|
||||||
/** |
/** |
||||||
* Created by lyy on 2017/2/28. |
* Created by lyy on 2017/2/28. |
||||||
*/ |
*/ |
||||||
abstract class AbsDTarget<TARGET extends AbsDTarget> extends AbsTarget<TARGET> { |
abstract class AbsDTarget<TARGET extends AbsDTarget> extends AbsTarget<TARGET> { |
||||||
|
|
||||||
/** |
/** |
||||||
* 更新下载url |
* 更新下载url |
||||||
* |
* |
||||||
* @param newUrl 新的下载url |
* @param newUrl 新的下载url |
||||||
*/ |
*/ |
||||||
public abstract TARGET updateUrl(String newUrl); |
public abstract TARGET updateUrl(String newUrl); |
||||||
|
|
||||||
/** |
/** |
||||||
* 将任务设置为最高优先级任务,最高优先级任务有以下特点: |
* 将任务设置为最高优先级任务,最高优先级任务有以下特点: |
||||||
* 1、在下载队列中,有且只有一个最高优先级任务 |
* 1、在下载队列中,有且只有一个最高优先级任务 |
||||||
* 2、最高优先级任务会一直存在,直到用户手动暂停或任务完成 |
* 2、最高优先级任务会一直存在,直到用户手动暂停或任务完成 |
||||||
* 3、任务调度器不会暂停最高优先级任务 |
* 3、任务调度器不会暂停最高优先级任务 |
||||||
* 4、用户手动暂停或任务完成后,第二次重新执行该任务,该命令将失效 |
* 4、用户手动暂停或任务完成后,第二次重新执行该任务,该命令将失效 |
||||||
* 5、如果下载队列中已经满了,则会停止队尾的任务,当高优先级任务完成后,该队尾任务将自动执行 |
* 5、如果下载队列中已经满了,则会停止队尾的任务,当高优先级任务完成后,该队尾任务将自动执行 |
||||||
* 6、把任务设置为最高优先级任务后,将自动执行任务,不需要重新调用start()启动任务 |
* 6、把任务设置为最高优先级任务后,将自动执行任务,不需要重新调用start()启动任务 |
||||||
*/ |
*/ |
||||||
public void setHighestPriority() { |
public void setHighestPriority() { |
||||||
if (checkEntity()) { |
if (checkConfig()) { |
||||||
AriaManager.getInstance(AriaManager.APP) |
AriaManager.getInstance(AriaManager.APP) |
||||||
.setCmd( |
.setCmd( |
||||||
CommonUtil.createNormalCmd(getTaskWrapper(), NormalCmdFactory.TASK_HIGHEST_PRIORITY, |
CommonUtil.createNormalCmd(getTaskWrapper(), NormalCmdFactory.TASK_HIGHEST_PRIORITY, |
||||||
checkTaskType())) |
checkTaskType())) |
||||||
.exe(); |
.exe(); |
||||||
} |
} |
||||||
} |
} |
||||||
|
|
||||||
@Override public DownloadEntity getEntity() { |
@Override public DownloadEntity getEntity() { |
||||||
return (DownloadEntity) super.getEntity(); |
return (DownloadEntity) super.getEntity(); |
||||||
} |
} |
||||||
} |
} |
||||||
|
@ -1,155 +1,155 @@ |
|||||||
/* |
/* |
||||||
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
|
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
|
||||||
* |
* |
||||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||||
* you may not use this file except in compliance with the License. |
* you may not use this file except in compliance with the License. |
||||||
* You may obtain a copy of the License at |
* You may obtain a copy of the License at |
||||||
* |
* |
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
* |
* |
||||||
* Unless required by applicable law or agreed to in writing, software |
* Unless required by applicable law or agreed to in writing, software |
||||||
* distributed under the License is distributed on an "AS IS" BASIS, |
* distributed under the License is distributed on an "AS IS" BASIS, |
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||||
* See the License for the specific language governing permissions and |
* See the License for the specific language governing permissions and |
||||||
* limitations under the License. |
* limitations under the License. |
||||||
*/ |
*/ |
||||||
package com.arialyy.aria.core.download; |
package com.arialyy.aria.core.download; |
||||||
|
|
||||||
import android.support.annotation.CheckResult; |
import android.support.annotation.CheckResult; |
||||||
import android.support.annotation.NonNull; |
import android.support.annotation.NonNull; |
||||||
import android.text.TextUtils; |
import android.text.TextUtils; |
||||||
import com.arialyy.aria.core.common.ftp.FTPSDelegate; |
import com.arialyy.aria.core.common.ftp.FTPSDelegate; |
||||||
import com.arialyy.aria.core.common.ftp.FtpDelegate; |
import com.arialyy.aria.core.common.ftp.FtpDelegate; |
||||||
import com.arialyy.aria.core.inf.AbsTaskWrapper; |
import com.arialyy.aria.core.inf.AbsTaskWrapper; |
||||||
import com.arialyy.aria.core.inf.IFtpTarget; |
import com.arialyy.aria.core.inf.IFtpTarget; |
||||||
import com.arialyy.aria.util.ALog; |
import com.arialyy.aria.util.ALog; |
||||||
import com.arialyy.aria.util.CommonUtil; |
import com.arialyy.aria.util.CommonUtil; |
||||||
import java.net.Proxy; |
import java.net.Proxy; |
||||||
|
|
||||||
/** |
/** |
||||||
* Created by lyy on 2016/12/5. |
* Created by lyy on 2016/12/5. |
||||||
* https://github.com/AriaLyy/Aria
|
* https://github.com/AriaLyy/Aria
|
||||||
*/ |
*/ |
||||||
public class FtpDownloadTarget extends AbsDTarget<FtpDownloadTarget> |
public class FtpDownloadTarget extends AbsDTarget<FtpDownloadTarget> |
||||||
implements IFtpTarget<FtpDownloadTarget> { |
implements IFtpTarget<FtpDownloadTarget> { |
||||||
private FtpDelegate<FtpDownloadTarget> mFtpDelegate; |
private FtpDelegate<FtpDownloadTarget> mFtpDelegate; |
||||||
private DNormalDelegate<FtpDownloadTarget> mNormalDelegate; |
private DNormalDelegate<FtpDownloadTarget> mNormalDelegate; |
||||||
|
|
||||||
FtpDownloadTarget(DownloadEntity entity, String targetName) { |
FtpDownloadTarget(DownloadEntity entity, String targetName) { |
||||||
this(entity.getUrl(), targetName); |
this(entity.getUrl(), targetName); |
||||||
} |
} |
||||||
|
|
||||||
FtpDownloadTarget(String url, String targetName) { |
FtpDownloadTarget(String url, String targetName) { |
||||||
mNormalDelegate = new DNormalDelegate<>(this, url, targetName); |
mNormalDelegate = new DNormalDelegate<>(this, url, targetName); |
||||||
init(); |
init(); |
||||||
} |
} |
||||||
|
|
||||||
private void init() { |
private void init() { |
||||||
int lastIndex = mNormalDelegate.getUrl().lastIndexOf("/"); |
int lastIndex = mNormalDelegate.getUrl().lastIndexOf("/"); |
||||||
getEntity().setFileName(mNormalDelegate.getUrl().substring(lastIndex + 1)); |
getEntity().setFileName(mNormalDelegate.getUrl().substring(lastIndex + 1)); |
||||||
getTaskWrapper().asFtp().setUrlEntity(CommonUtil.getFtpUrlInfo(mNormalDelegate.getUrl())); |
getTaskWrapper().asFtp().setUrlEntity(CommonUtil.getFtpUrlInfo(mNormalDelegate.getUrl())); |
||||||
getTaskWrapper().setRequestType(AbsTaskWrapper.D_FTP); |
getTaskWrapper().setRequestType(AbsTaskWrapper.D_FTP); |
||||||
|
|
||||||
mFtpDelegate = new FtpDelegate<>(this); |
mFtpDelegate = new FtpDelegate<>(this); |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
* 是否是FTPS协议 |
* 是否是FTPS协议 |
||||||
* 如果是FTPS协议,需要使用{@link FTPSDelegate#setStorePath(String)} 、{@link FTPSDelegate#setAlias(String)} |
* 如果是FTPS协议,需要使用{@link FTPSDelegate#setStorePath(String)} 、{@link FTPSDelegate#setAlias(String)} |
||||||
* 设置证书信息 |
* 设置证书信息 |
||||||
*/ |
*/ |
||||||
@CheckResult |
@CheckResult |
||||||
public FTPSDelegate<FtpDownloadTarget> asFtps() { |
public FTPSDelegate<FtpDownloadTarget> asFtps() { |
||||||
getTaskWrapper().asFtp().getUrlEntity().isFtps = true; |
getTaskWrapper().asFtp().getUrlEntity().isFtps = true; |
||||||
return new FTPSDelegate<>(this); |
return new FTPSDelegate<>(this); |
||||||
} |
} |
||||||
|
|
||||||
@Override protected boolean checkEntity() { |
@Override protected boolean checkEntity() { |
||||||
if (getTaskWrapper().asFtp().getUrlEntity().isFtps) { |
if (getTaskWrapper().asFtp().getUrlEntity().isFtps) { |
||||||
if (TextUtils.isEmpty(getTaskWrapper().asFtp().getUrlEntity().storePath)) { |
if (TextUtils.isEmpty(getTaskWrapper().asFtp().getUrlEntity().storePath)) { |
||||||
ALog.e(TAG, "证书路径为空"); |
ALog.e(TAG, "证书路径为空"); |
||||||
return false; |
return false; |
||||||
} |
} |
||||||
if (TextUtils.isEmpty(getTaskWrapper().asFtp().getUrlEntity().keyAlias)) { |
if (TextUtils.isEmpty(getTaskWrapper().asFtp().getUrlEntity().keyAlias)) { |
||||||
ALog.e(TAG, "证书别名为空"); |
ALog.e(TAG, "证书别名为空"); |
||||||
return false; |
return false; |
||||||
} |
} |
||||||
} |
} |
||||||
return mNormalDelegate.checkEntity(); |
return mNormalDelegate.checkEntity(); |
||||||
} |
} |
||||||
|
|
||||||
@Override public boolean isRunning() { |
@Override public boolean isRunning() { |
||||||
return mNormalDelegate.isRunning(); |
return mNormalDelegate.isRunning(); |
||||||
} |
} |
||||||
|
|
||||||
@Override public boolean taskExists() { |
@Override public boolean taskExists() { |
||||||
return mNormalDelegate.taskExists(); |
return mNormalDelegate.taskExists(); |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
* 设置文件保存文件夹路径 |
* 设置文件保存文件夹路径 |
||||||
* |
* |
||||||
* @param filePath 文件保存路径 |
* @param filePath 文件保存路径 |
||||||
* @deprecated {@link #setFilePath(String)} 请使用这个api |
* @deprecated {@link #setFilePath(String)} 请使用这个api |
||||||
*/ |
*/ |
||||||
@Deprecated |
@Deprecated |
||||||
@CheckResult |
@CheckResult |
||||||
public FtpDownloadTarget setDownloadPath(@NonNull String filePath) { |
public FtpDownloadTarget setDownloadPath(@NonNull String filePath) { |
||||||
return setFilePath(filePath); |
return setFilePath(filePath); |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
* 设置文件保存文件夹路径 |
* 设置文件保存文件夹路径 |
||||||
* 关于文件名: |
* 关于文件名: |
||||||
* 1、如果保存路径是该文件的保存路径,如:/mnt/sdcard/file.zip,则使用路径中的文件名file.zip |
* 1、如果保存路径是该文件的保存路径,如:/mnt/sdcard/file.zip,则使用路径中的文件名file.zip |
||||||
* 2、如果保存路径是文件夹路径,如:/mnt/sdcard/,则使用FTP服务器该文件的文件名 |
* 2、如果保存路径是文件夹路径,如:/mnt/sdcard/,则使用FTP服务器该文件的文件名 |
||||||
*/ |
*/ |
||||||
@CheckResult |
@CheckResult |
||||||
public FtpDownloadTarget setFilePath(@NonNull String filePath) { |
public FtpDownloadTarget setFilePath(@NonNull String filePath) { |
||||||
mNormalDelegate.setTempFilePath(filePath); |
mNormalDelegate.setTempFilePath(filePath); |
||||||
return this; |
return this; |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
* 设置文件存储路径,如果需要修改新的文件名,修改路径便可。 |
* 设置文件存储路径,如果需要修改新的文件名,修改路径便可。 |
||||||
* 如:原文件路径 /mnt/sdcard/test.zip |
* 如:原文件路径 /mnt/sdcard/test.zip |
||||||
* 如果需要将test.zip改为game.zip,只需要重新设置文件路径为:/mnt/sdcard/game.zip |
* 如果需要将test.zip改为game.zip,只需要重新设置文件路径为:/mnt/sdcard/game.zip |
||||||
* |
* |
||||||
* @param filePath 路径必须为文件路径,不能为文件夹路径 |
* @param filePath 路径必须为文件路径,不能为文件夹路径 |
||||||
* @param forceDownload {@code true}强制下载,不考虑文件路径是否被占用 |
* @param forceDownload {@code true}强制下载,不考虑文件路径是否被占用 |
||||||
*/ |
*/ |
||||||
@CheckResult |
@CheckResult |
||||||
public FtpDownloadTarget setFilePath(@NonNull String filePath, boolean forceDownload) { |
public FtpDownloadTarget setFilePath(@NonNull String filePath, boolean forceDownload) { |
||||||
mNormalDelegate.setTempFilePath(filePath); |
mNormalDelegate.setTempFilePath(filePath); |
||||||
mNormalDelegate.setForceDownload(forceDownload); |
mNormalDelegate.setForceDownload(forceDownload); |
||||||
return this; |
return this; |
||||||
} |
} |
||||||
|
|
||||||
@Override public int getTargetType() { |
@Override public int getTargetType() { |
||||||
return FTP; |
return D_FTP; |
||||||
} |
} |
||||||
|
|
||||||
@CheckResult |
@CheckResult |
||||||
@Override public FtpDownloadTarget charSet(String charSet) { |
@Override public FtpDownloadTarget charSet(String charSet) { |
||||||
return mFtpDelegate.charSet(charSet); |
return mFtpDelegate.charSet(charSet); |
||||||
} |
} |
||||||
|
|
||||||
@CheckResult |
@CheckResult |
||||||
@Override public FtpDownloadTarget login(String userName, String password) { |
@Override public FtpDownloadTarget login(String userName, String password) { |
||||||
return mFtpDelegate.login(userName, password); |
return mFtpDelegate.login(userName, password); |
||||||
} |
} |
||||||
|
|
||||||
@CheckResult |
@CheckResult |
||||||
@Override public FtpDownloadTarget login(String userName, String password, String account) { |
@Override public FtpDownloadTarget login(String userName, String password, String account) { |
||||||
return mFtpDelegate.login(userName, password, account); |
return mFtpDelegate.login(userName, password, account); |
||||||
} |
} |
||||||
|
|
||||||
@CheckResult |
@CheckResult |
||||||
@Override public FtpDownloadTarget setProxy(Proxy proxy) { |
@Override public FtpDownloadTarget setProxy(Proxy proxy) { |
||||||
return mFtpDelegate.setProxy(proxy); |
return mFtpDelegate.setProxy(proxy); |
||||||
} |
} |
||||||
|
|
||||||
@Override public FtpDownloadTarget updateUrl(String newUrl) { |
@Override public FtpDownloadTarget updateUrl(String newUrl) { |
||||||
return mNormalDelegate.updateUrl(newUrl); |
return mNormalDelegate.updateUrl(newUrl); |
||||||
} |
} |
||||||
} |
} |
||||||
|
@ -1,50 +1,50 @@ |
|||||||
/* |
/* |
||||||
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
|
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
|
||||||
* |
* |
||||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||||
* you may not use this file except in compliance with the License. |
* you may not use this file except in compliance with the License. |
||||||
* You may obtain a copy of the License at |
* You may obtain a copy of the License at |
||||||
* |
* |
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
* |
* |
||||||
* Unless required by applicable law or agreed to in writing, software |
* Unless required by applicable law or agreed to in writing, software |
||||||
* distributed under the License is distributed on an "AS IS" BASIS, |
* distributed under the License is distributed on an "AS IS" BASIS, |
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||||
* See the License for the specific language governing permissions and |
* See the License for the specific language governing permissions and |
||||||
* limitations under the License. |
* limitations under the License. |
||||||
*/ |
*/ |
||||||
package com.arialyy.aria.core.inf; |
package com.arialyy.aria.core.inf; |
||||||
|
|
||||||
import android.support.annotation.CheckResult; |
import android.support.annotation.CheckResult; |
||||||
import android.support.annotation.NonNull; |
import android.support.annotation.NonNull; |
||||||
import java.net.Proxy; |
import java.net.Proxy; |
||||||
import java.util.Map; |
import java.util.Map; |
||||||
|
|
||||||
/** |
/** |
||||||
* Created by laoyuyu on 2018/3/9. |
* Created by laoyuyu on 2018/3/9. |
||||||
* HTTP Header功能接口 |
* D_HTTP Header功能接口 |
||||||
*/ |
*/ |
||||||
public interface IHttpHeaderDelegate<TARGET extends ITargetHandler> { |
public interface IHttpHeaderDelegate<TARGET extends ITargetHandler> { |
||||||
|
|
||||||
/** |
/** |
||||||
* 给url请求添加Header数据 |
* 给url请求添加Header数据 |
||||||
* 如果新的header数据和数据保存的不一致,则更新数据库中对应的header数据 |
* 如果新的header数据和数据保存的不一致,则更新数据库中对应的header数据 |
||||||
* |
* |
||||||
* @param key header对应的key |
* @param key header对应的key |
||||||
* @param value header对应的value |
* @param value header对应的value |
||||||
*/ |
*/ |
||||||
@CheckResult |
@CheckResult |
||||||
TARGET addHeader(@NonNull String key, @NonNull String value); |
TARGET addHeader(@NonNull String key, @NonNull String value); |
||||||
|
|
||||||
/** |
/** |
||||||
* 给url请求添加一组header数据 |
* 给url请求添加一组header数据 |
||||||
* 如果新的header数据和数据保存的不一致,则更新数据库中对应的header数据 |
* 如果新的header数据和数据保存的不一致,则更新数据库中对应的header数据 |
||||||
* |
* |
||||||
* @param headers 一组http header数据 |
* @param headers 一组http header数据 |
||||||
*/ |
*/ |
||||||
@CheckResult |
@CheckResult |
||||||
TARGET addHeaders(Map<String, String> headers); |
TARGET addHeaders(Map<String, String> headers); |
||||||
|
|
||||||
@CheckResult |
@CheckResult |
||||||
TARGET setUrlProxy(Proxy proxy); |
TARGET setUrlProxy(Proxy proxy); |
||||||
} |
} |
||||||
|
@ -1,77 +1,79 @@ |
|||||||
/* |
/* |
||||||
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
|
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
|
||||||
* |
* |
||||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||||
* you may not use this file except in compliance with the License. |
* you may not use this file except in compliance with the License. |
||||||
* You may obtain a copy of the License at |
* You may obtain a copy of the License at |
||||||
* |
* |
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
* |
* |
||||||
* Unless required by applicable law or agreed to in writing, software |
* Unless required by applicable law or agreed to in writing, software |
||||||
* distributed under the License is distributed on an "AS IS" BASIS, |
* distributed under the License is distributed on an "AS IS" BASIS, |
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||||
* See the License for the specific language governing permissions and |
* See the License for the specific language governing permissions and |
||||||
* limitations under the License. |
* limitations under the License. |
||||||
*/ |
*/ |
||||||
package com.arialyy.aria.core.inf; |
package com.arialyy.aria.core.inf; |
||||||
|
|
||||||
/** |
/** |
||||||
* Created by AriaL on 2017/6/29. |
* Created by AriaL on 2017/6/29. |
||||||
* 任务接收器的控制接口,处理添加任务、开始任务、停止任务、删除任务等功能 |
* 任务接收器的控制接口,处理添加任务、开始任务、停止任务、删除任务等功能 |
||||||
*/ |
*/ |
||||||
public interface ITargetHandler { |
public interface ITargetHandler { |
||||||
int HTTP = 1; |
int D_HTTP = 1; |
||||||
int FTP = 2; |
int U_HTTP = 2; |
||||||
//HTTP任务组
|
int U_FTP = 3; |
||||||
int GROUP_HTTP = 3; |
int D_FTP = 4; |
||||||
//FTP文件夹
|
//HTTP任务组
|
||||||
int GROUP_FTP_DIR = 4; |
int GROUP_HTTP = 5; |
||||||
|
//FTP文件夹
|
||||||
/** |
int GROUP_FTP_DIR = 6; |
||||||
* 添加任务 |
|
||||||
*/ |
/** |
||||||
void add(); |
* 添加任务 |
||||||
|
*/ |
||||||
/** |
void add(); |
||||||
* 开始下载 |
|
||||||
*/ |
/** |
||||||
void start(); |
* 开始下载 |
||||||
|
*/ |
||||||
/** |
void start(); |
||||||
* 停止下载 |
|
||||||
*/ |
/** |
||||||
void stop(); |
* 停止下载 |
||||||
|
*/ |
||||||
/** |
void stop(); |
||||||
* 恢复下载 |
|
||||||
*/ |
/** |
||||||
void resume(); |
* 恢复下载 |
||||||
|
*/ |
||||||
/** |
void resume(); |
||||||
* 取消下载 |
|
||||||
*/ |
/** |
||||||
void cancel(); |
* 取消下载 |
||||||
|
*/ |
||||||
/** |
void cancel(); |
||||||
* 保存修改 |
|
||||||
*/ |
/** |
||||||
void save(); |
* 保存修改 |
||||||
|
*/ |
||||||
/** |
void save(); |
||||||
* 删除任务 |
|
||||||
* |
/** |
||||||
* @param removeFile {@code true} 不仅删除任务数据库记录,还会删除已经删除完成的文件 |
* 删除任务 |
||||||
* {@code false}如果任务已经完成,只删除任务数据库记录, |
* |
||||||
*/ |
* @param removeFile {@code true} 不仅删除任务数据库记录,还会删除已经删除完成的文件 |
||||||
void cancel(boolean removeFile); |
* {@code false}如果任务已经完成,只删除任务数据库记录, |
||||||
|
*/ |
||||||
/** |
void cancel(boolean removeFile); |
||||||
* 任务重试 |
|
||||||
*/ |
/** |
||||||
void reTry(); |
* 任务重试 |
||||||
|
*/ |
||||||
/** |
void reTry(); |
||||||
* 重新下载 |
|
||||||
*/ |
/** |
||||||
void reStart(); |
* 重新下载 |
||||||
} |
*/ |
||||||
|
void reStart(); |
||||||
|
} |
||||||
|
@ -1,133 +1,139 @@ |
|||||||
/* |
/* |
||||||
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
|
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
|
||||||
* |
* |
||||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||||
* you may not use this file except in compliance with the License. |
* you may not use this file except in compliance with the License. |
||||||
* You may obtain a copy of the License at |
* You may obtain a copy of the License at |
||||||
* |
* |
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
* |
* |
||||||
* Unless required by applicable law or agreed to in writing, software |
* Unless required by applicable law or agreed to in writing, software |
||||||
* distributed under the License is distributed on an "AS IS" BASIS, |
* distributed under the License is distributed on an "AS IS" BASIS, |
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||||
* See the License for the specific language governing permissions and |
* See the License for the specific language governing permissions and |
||||||
* limitations under the License. |
* limitations under the License. |
||||||
*/ |
*/ |
||||||
package com.arialyy.aria.core.inf; |
package com.arialyy.aria.core.inf; |
||||||
|
|
||||||
import com.arialyy.aria.core.download.DownloadGroupTask; |
import com.arialyy.aria.core.download.DownloadGroupTask; |
||||||
import com.arialyy.aria.core.download.DownloadTask; |
import com.arialyy.aria.core.download.DownloadTask; |
||||||
import com.arialyy.aria.core.upload.UploadTask; |
import com.arialyy.aria.core.upload.UploadTask; |
||||||
|
|
||||||
/** |
/** |
||||||
* Created by lyy on 2017/2/13. |
* Created by lyy on 2017/2/13. |
||||||
* 任务接口{@link DownloadTask}、{@link UploadTask}、{@link DownloadGroupTask} |
* 任务接口{@link DownloadTask}、{@link UploadTask}、{@link DownloadGroupTask} |
||||||
*/ |
*/ |
||||||
public interface ITask<TASK_WRAPPER extends AbsTaskWrapper> { |
public interface ITask<TASK_WRAPPER extends AbsTaskWrapper> { |
||||||
|
|
||||||
/** |
/** |
||||||
* 普通下载任务 |
* 普通下载任务 |
||||||
*/ |
*/ |
||||||
int DOWNLOAD = 1; |
int DOWNLOAD = 1; |
||||||
/** |
/** |
||||||
* 上传任务 |
* 上传任务 |
||||||
*/ |
*/ |
||||||
int UPLOAD = 2; |
int UPLOAD = 2; |
||||||
/** |
/** |
||||||
* 组合任务 |
* 组合任务 |
||||||
*/ |
*/ |
||||||
int DOWNLOAD_GROUP = 3; |
int DOWNLOAD_GROUP = 3; |
||||||
/** |
/** |
||||||
* 组合任务的子任务 |
* 组合任务的子任务 |
||||||
*/ |
*/ |
||||||
int DOWNLOAD_GROUP_SUB = 4; |
int DOWNLOAD_GROUP_SUB = 4; |
||||||
/** |
/** |
||||||
* 未知 |
* 填充的 |
||||||
*/ |
*/ |
||||||
int OTHER = -1; |
int TEMP = 5; |
||||||
|
/** |
||||||
/** |
* 未知 |
||||||
* 获取任务类型 |
*/ |
||||||
* |
int OTHER = -1; |
||||||
* @return {@link #DOWNLOAD}、{@link #UPLOAD}、{@link #DOWNLOAD_GROUP} |
|
||||||
*/ |
/** |
||||||
int getTaskType(); |
* 获取任务类型 |
||||||
|
* |
||||||
/** |
* @return {@link #DOWNLOAD}、{@link #UPLOAD}、{@link #DOWNLOAD_GROUP} |
||||||
* 获取下载状态 |
*/ |
||||||
*/ |
int getTaskType(); |
||||||
int getState(); |
|
||||||
|
/** |
||||||
/** |
* 获取下载状态 |
||||||
* 唯一标识符,DownloadTask 为下载地址,UploadTask 为文件路径 |
*/ |
||||||
*/ |
int getState(); |
||||||
String getKey(); |
|
||||||
|
/** |
||||||
/** |
* 唯一标识符,DownloadTask 为下载地址,UploadTask 为文件路径 |
||||||
* 任务是否正在执行 |
*/ |
||||||
* |
String getKey(); |
||||||
* @return true,正在执行; |
|
||||||
*/ |
/** |
||||||
boolean isRunning(); |
* 任务是否正在执行 |
||||||
|
* |
||||||
/** |
* @return true,正在执行; |
||||||
* 获取信息实体 |
*/ |
||||||
*/ |
boolean isRunning(); |
||||||
TASK_WRAPPER getTaskWrapper(); |
|
||||||
|
/** |
||||||
void start(); |
* 获取信息实体 |
||||||
|
*/ |
||||||
/** |
TASK_WRAPPER getTaskWrapper(); |
||||||
* 停止任务 |
|
||||||
*/ |
void start(); |
||||||
void stop(); |
|
||||||
|
/** |
||||||
/** |
* 停止任务 |
||||||
* 停止任务 |
*/ |
||||||
* |
void stop(); |
||||||
* @param type {@code 0}默认操作,{@code 1}停止任务不自动执行下一任务 |
|
||||||
*/ |
/** |
||||||
void stop(int type); |
* 停止任务 |
||||||
|
* |
||||||
/** |
* @param type {@code 0}默认操作,{@code 1}停止任务不自动执行下一任务 |
||||||
* 删除任务 |
*/ |
||||||
*/ |
void stop(int type); |
||||||
void cancel(); |
|
||||||
|
/** |
||||||
/** |
* 删除任务 |
||||||
* 原始byte速度 |
*/ |
||||||
*/ |
void cancel(); |
||||||
long getSpeed(); |
|
||||||
|
/** |
||||||
/** |
* 读取扩展数据 |
||||||
* 转换单位后的速度 |
*/ |
||||||
*/ |
Object getExpand(String key); |
||||||
String getConvertSpeed(); |
|
||||||
|
/** |
||||||
/** |
* 任务是否停止了 |
||||||
* 获取百分比进度 |
* |
||||||
*/ |
* @return {@code true}任务已经停止 |
||||||
int getPercent(); |
*/ |
||||||
|
boolean isStop(); |
||||||
/** |
|
||||||
* 原始文件byte长度 |
/** |
||||||
*/ |
* 任务是否取消了 |
||||||
long getFileSize(); |
* |
||||||
|
* @return {@code true}任务已经取消 |
||||||
/** |
*/ |
||||||
* 转换单位后的文件长度 |
boolean isCancel(); |
||||||
*/ |
|
||||||
String getConvertFileSize(); |
/** |
||||||
|
* 任务是否需要重试 |
||||||
/** |
* |
||||||
* 获取当前进度 |
* @return {@code true}任务已经取消 |
||||||
*/ |
*/ |
||||||
long getCurrentProgress(); |
boolean isNeedRetry(); |
||||||
|
|
||||||
/** |
/** |
||||||
* 获取单位转换后的进度 |
* 获取任务名,也就是文件名 |
||||||
* |
*/ |
||||||
* @return 返回 3mb |
String getTaskName(); |
||||||
*/ |
|
||||||
String getConvertCurrentProgress(); |
/** |
||||||
} |
* 任务的调度类型 |
||||||
|
* {@link TaskSchedulerType} |
||||||
|
*/ |
||||||
|
int getSchedulerType(); |
||||||
|
|
||||||
|
|
||||||
|
} |
||||||
|
@ -1,104 +1,104 @@ |
|||||||
/* |
/* |
||||||
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
|
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
|
||||||
* |
* |
||||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||||
* you may not use this file except in compliance with the License. |
* you may not use this file except in compliance with the License. |
||||||
* You may obtain a copy of the License at |
* You may obtain a copy of the License at |
||||||
* |
* |
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
* |
* |
||||||
* Unless required by applicable law or agreed to in writing, software |
* Unless required by applicable law or agreed to in writing, software |
||||||
* distributed under the License is distributed on an "AS IS" BASIS, |
* distributed under the License is distributed on an "AS IS" BASIS, |
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||||
* See the License for the specific language governing permissions and |
* See the License for the specific language governing permissions and |
||||||
* limitations under the License. |
* limitations under the License. |
||||||
*/ |
*/ |
||||||
package com.arialyy.aria.core.upload; |
package com.arialyy.aria.core.upload; |
||||||
|
|
||||||
import android.support.annotation.CheckResult; |
import android.support.annotation.CheckResult; |
||||||
import com.arialyy.aria.core.FtpUrlEntity; |
import com.arialyy.aria.core.FtpUrlEntity; |
||||||
import com.arialyy.aria.core.common.ftp.FTPSDelegate; |
import com.arialyy.aria.core.common.ftp.FTPSDelegate; |
||||||
import com.arialyy.aria.core.common.ftp.FtpDelegate; |
import com.arialyy.aria.core.common.ftp.FtpDelegate; |
||||||
import com.arialyy.aria.core.inf.AbsTaskWrapper; |
import com.arialyy.aria.core.inf.AbsTaskWrapper; |
||||||
import com.arialyy.aria.core.inf.IFtpTarget; |
import com.arialyy.aria.core.inf.IFtpTarget; |
||||||
import com.arialyy.aria.util.CheckUtil; |
import com.arialyy.aria.util.CheckUtil; |
||||||
import java.net.Proxy; |
import java.net.Proxy; |
||||||
|
|
||||||
/** |
/** |
||||||
* Created by Aria.Lao on 2017/7/27. |
* Created by Aria.Lao on 2017/7/27. |
||||||
* ftp单任务上传 |
* ftp单任务上传 |
||||||
*/ |
*/ |
||||||
public class FtpUploadTarget extends AbsUploadTarget<FtpUploadTarget> |
public class FtpUploadTarget extends AbsUploadTarget<FtpUploadTarget> |
||||||
implements IFtpTarget<FtpUploadTarget> { |
implements IFtpTarget<FtpUploadTarget> { |
||||||
private FtpDelegate<FtpUploadTarget> mFtpDelegate; |
private FtpDelegate<FtpUploadTarget> mFtpDelegate; |
||||||
private UNormalDelegate<FtpUploadTarget> mNormalDelegate; |
private UNormalDelegate<FtpUploadTarget> mNormalDelegate; |
||||||
|
|
||||||
FtpUploadTarget(String filePath, String targetName) { |
FtpUploadTarget(String filePath, String targetName) { |
||||||
mNormalDelegate = new UNormalDelegate<>(this, filePath, targetName); |
mNormalDelegate = new UNormalDelegate<>(this, filePath, targetName); |
||||||
initTask(); |
initTask(); |
||||||
} |
} |
||||||
|
|
||||||
private void initTask() { |
private void initTask() { |
||||||
getTaskWrapper().setRequestType(AbsTaskWrapper.U_FTP); |
getTaskWrapper().setRequestType(AbsTaskWrapper.U_FTP); |
||||||
mFtpDelegate = new FtpDelegate<>(this); |
mFtpDelegate = new FtpDelegate<>(this); |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
* 设置上传路径 |
* 设置上传路径 |
||||||
* |
* |
||||||
* @param tempUrl 上传路径 |
* @param tempUrl 上传路径 |
||||||
*/ |
*/ |
||||||
public FtpUploadTarget setUploadUrl(String tempUrl) { |
public FtpUploadTarget setUploadUrl(String tempUrl) { |
||||||
mNormalDelegate.setTempUrl(tempUrl); |
mNormalDelegate.setTempUrl(tempUrl); |
||||||
return this; |
return this; |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
* 是否是FTPS协议 |
* 是否是FTPS协议 |
||||||
* 如果是FTPS协议,需要使用{@link FTPSDelegate#setStorePath(String)} 、{@link FTPSDelegate#setAlias(String)} |
* 如果是FTPS协议,需要使用{@link FTPSDelegate#setStorePath(String)} 、{@link FTPSDelegate#setAlias(String)} |
||||||
* 设置证书信息 |
* 设置证书信息 |
||||||
*/ |
*/ |
||||||
@CheckResult |
@CheckResult |
||||||
public FTPSDelegate<FtpUploadTarget> asFtps() { |
public FTPSDelegate<FtpUploadTarget> asFtps() { |
||||||
if (getTaskWrapper().asFtp().getUrlEntity() == null) { |
if (getTaskWrapper().asFtp().getUrlEntity() == null) { |
||||||
FtpUrlEntity urlEntity = new FtpUrlEntity(); |
FtpUrlEntity urlEntity = new FtpUrlEntity(); |
||||||
urlEntity.isFtps = true; |
urlEntity.isFtps = true; |
||||||
getTaskWrapper().asFtp().setUrlEntity(urlEntity); |
getTaskWrapper().asFtp().setUrlEntity(urlEntity); |
||||||
} |
} |
||||||
return new FTPSDelegate<>(this); |
return new FTPSDelegate<>(this); |
||||||
} |
} |
||||||
|
|
||||||
@CheckResult |
@CheckResult |
||||||
@Override public FtpUploadTarget charSet(String charSet) { |
@Override public FtpUploadTarget charSet(String charSet) { |
||||||
return mFtpDelegate.charSet(charSet); |
return mFtpDelegate.charSet(charSet); |
||||||
} |
} |
||||||
|
|
||||||
@Override public FtpUploadTarget login(String userName, String password) { |
@Override public FtpUploadTarget login(String userName, String password) { |
||||||
return mFtpDelegate.login(userName, password); |
return mFtpDelegate.login(userName, password); |
||||||
} |
} |
||||||
|
|
||||||
@Override public FtpUploadTarget login(String userName, String password, String account) { |
@Override public FtpUploadTarget login(String userName, String password, String account) { |
||||||
CheckUtil.checkFtpUploadUrl(mNormalDelegate.getTempUrl()); |
CheckUtil.checkFtpUploadUrl(mNormalDelegate.getTempUrl()); |
||||||
return mFtpDelegate.login(userName, password, account); |
return mFtpDelegate.login(userName, password, account); |
||||||
} |
} |
||||||
|
|
||||||
@Override public FtpUploadTarget setProxy(Proxy proxy) { |
@Override public FtpUploadTarget setProxy(Proxy proxy) { |
||||||
return mFtpDelegate.setProxy(proxy); |
return mFtpDelegate.setProxy(proxy); |
||||||
} |
} |
||||||
|
|
||||||
@Override protected boolean checkEntity() { |
@Override protected boolean checkEntity() { |
||||||
return mNormalDelegate.checkEntity(); |
return mNormalDelegate.checkEntity(); |
||||||
} |
} |
||||||
|
|
||||||
@Override public boolean isRunning() { |
@Override public boolean isRunning() { |
||||||
return mNormalDelegate.isRunning(); |
return mNormalDelegate.isRunning(); |
||||||
} |
} |
||||||
|
|
||||||
@Override public boolean taskExists() { |
@Override public boolean taskExists() { |
||||||
return mNormalDelegate.taskExists(); |
return mNormalDelegate.taskExists(); |
||||||
} |
} |
||||||
|
|
||||||
@Override public int getTargetType() { |
@Override public int getTargetType() { |
||||||
return FTP; |
return U_FTP; |
||||||
} |
} |
||||||
} |
} |
||||||
|
@ -1,125 +1,125 @@ |
|||||||
/* |
/* |
||||||
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
|
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
|
||||||
* |
* |
||||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||||
* you may not use this file except in compliance with the License. |
* you may not use this file except in compliance with the License. |
||||||
* You may obtain a copy of the License at |
* You may obtain a copy of the License at |
||||||
* |
* |
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
* |
* |
||||||
* Unless required by applicable law or agreed to in writing, software |
* Unless required by applicable law or agreed to in writing, software |
||||||
* distributed under the License is distributed on an "AS IS" BASIS, |
* distributed under the License is distributed on an "AS IS" BASIS, |
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||||
* See the License for the specific language governing permissions and |
* See the License for the specific language governing permissions and |
||||||
* limitations under the License. |
* limitations under the License. |
||||||
*/ |
*/ |
||||||
package com.arialyy.aria.core.upload; |
package com.arialyy.aria.core.upload; |
||||||
|
|
||||||
import android.support.annotation.CheckResult; |
import android.support.annotation.CheckResult; |
||||||
import android.support.annotation.NonNull; |
import android.support.annotation.NonNull; |
||||||
import com.arialyy.aria.core.common.http.HttpHeaderDelegate; |
import com.arialyy.aria.core.common.http.HttpHeaderDelegate; |
||||||
import com.arialyy.aria.core.common.http.PostDelegate; |
import com.arialyy.aria.core.common.http.PostDelegate; |
||||||
import com.arialyy.aria.core.inf.AbsTaskWrapper; |
import com.arialyy.aria.core.inf.AbsTaskWrapper; |
||||||
import com.arialyy.aria.core.inf.IHttpHeaderDelegate; |
import com.arialyy.aria.core.inf.IHttpHeaderDelegate; |
||||||
import java.net.Proxy; |
import java.net.Proxy; |
||||||
import java.util.Map; |
import java.util.Map; |
||||||
|
|
||||||
/** |
/** |
||||||
* Created by lyy on 2017/2/28. |
* Created by lyy on 2017/2/28. |
||||||
* http 单文件上传 |
* http 单文件上传 |
||||||
*/ |
*/ |
||||||
public class UploadTarget extends AbsUploadTarget<UploadTarget> |
public class UploadTarget extends AbsUploadTarget<UploadTarget> |
||||||
implements IHttpHeaderDelegate<UploadTarget> { |
implements IHttpHeaderDelegate<UploadTarget> { |
||||||
private HttpHeaderDelegate<UploadTarget> mHeaderDelegate; |
private HttpHeaderDelegate<UploadTarget> mHeaderDelegate; |
||||||
private UNormalDelegate<UploadTarget> mNormalDelegate; |
private UNormalDelegate<UploadTarget> mNormalDelegate; |
||||||
|
|
||||||
UploadTarget(String filePath, String targetName) { |
UploadTarget(String filePath, String targetName) { |
||||||
mNormalDelegate = new UNormalDelegate<>(this, filePath, targetName); |
mNormalDelegate = new UNormalDelegate<>(this, filePath, targetName); |
||||||
initTask(); |
initTask(); |
||||||
} |
} |
||||||
|
|
||||||
private void initTask() { |
private void initTask() { |
||||||
//http暂时不支持断点上传
|
//http暂时不支持断点上传
|
||||||
getTaskWrapper().setSupportBP(false); |
getTaskWrapper().setSupportBP(false); |
||||||
getTaskWrapper().setRequestType(AbsTaskWrapper.U_HTTP); |
getTaskWrapper().setRequestType(AbsTaskWrapper.U_HTTP); |
||||||
mHeaderDelegate = new HttpHeaderDelegate<>(this); |
mHeaderDelegate = new HttpHeaderDelegate<>(this); |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
* 设置上传路径 |
* 设置上传路径 |
||||||
* |
* |
||||||
* @param tempUrl 上传路径 |
* @param tempUrl 上传路径 |
||||||
*/ |
*/ |
||||||
public UploadTarget setUploadUrl(String tempUrl) { |
public UploadTarget setUploadUrl(String tempUrl) { |
||||||
mNormalDelegate.setTempUrl(tempUrl); |
mNormalDelegate.setTempUrl(tempUrl); |
||||||
return this; |
return this; |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
* Post处理 |
* Post处理 |
||||||
*/ |
*/ |
||||||
public PostDelegate asPost() { |
public PostDelegate asPost() { |
||||||
return new PostDelegate<>(this); |
return new PostDelegate<>(this); |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
* 设置userAgent |
* 设置userAgent |
||||||
*/ |
*/ |
||||||
@CheckResult |
@CheckResult |
||||||
public UploadTarget setUserAngent(@NonNull String userAgent) { |
public UploadTarget setUserAngent(@NonNull String userAgent) { |
||||||
getTaskWrapper().asHttp().setUserAgent(userAgent); |
getTaskWrapper().asHttp().setUserAgent(userAgent); |
||||||
return this; |
return this; |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
* 设置服务器需要的附件key |
* 设置服务器需要的附件key |
||||||
* |
* |
||||||
* @param attachment 附件key |
* @param attachment 附件key |
||||||
*/ |
*/ |
||||||
@CheckResult |
@CheckResult |
||||||
public UploadTarget setAttachment(@NonNull String attachment) { |
public UploadTarget setAttachment(@NonNull String attachment) { |
||||||
getTaskWrapper().asHttp().setAttachment(attachment); |
getTaskWrapper().asHttp().setAttachment(attachment); |
||||||
return this; |
return this; |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
* 设置上传文件类型 |
* 设置上传文件类型 |
||||||
* |
* |
||||||
* @param contentType tip:multipart/form-data |
* @param contentType tip:multipart/form-data |
||||||
*/ |
*/ |
||||||
@CheckResult |
@CheckResult |
||||||
public UploadTarget setContentType(String contentType) { |
public UploadTarget setContentType(String contentType) { |
||||||
getTaskWrapper().asHttp().setContentType(contentType); |
getTaskWrapper().asHttp().setContentType(contentType); |
||||||
return this; |
return this; |
||||||
} |
} |
||||||
|
|
||||||
@CheckResult |
@CheckResult |
||||||
@Override public UploadTarget addHeader(@NonNull String key, @NonNull String value) { |
@Override public UploadTarget addHeader(@NonNull String key, @NonNull String value) { |
||||||
return mHeaderDelegate.addHeader(key, value); |
return mHeaderDelegate.addHeader(key, value); |
||||||
} |
} |
||||||
|
|
||||||
@CheckResult |
@CheckResult |
||||||
@Override public UploadTarget addHeaders(Map<String, String> headers) { |
@Override public UploadTarget addHeaders(Map<String, String> headers) { |
||||||
return mHeaderDelegate.addHeaders(headers); |
return mHeaderDelegate.addHeaders(headers); |
||||||
} |
} |
||||||
|
|
||||||
@Override public UploadTarget setUrlProxy(Proxy proxy) { |
@Override public UploadTarget setUrlProxy(Proxy proxy) { |
||||||
return mHeaderDelegate.setUrlProxy(proxy); |
return mHeaderDelegate.setUrlProxy(proxy); |
||||||
} |
} |
||||||
|
|
||||||
@Override protected boolean checkEntity() { |
@Override protected boolean checkEntity() { |
||||||
return mNormalDelegate.checkEntity(); |
return mNormalDelegate.checkEntity(); |
||||||
} |
} |
||||||
|
|
||||||
@Override public boolean isRunning() { |
@Override public boolean isRunning() { |
||||||
return mNormalDelegate.isRunning(); |
return mNormalDelegate.isRunning(); |
||||||
} |
} |
||||||
|
|
||||||
@Override public boolean taskExists() { |
@Override public boolean taskExists() { |
||||||
return mNormalDelegate.taskExists(); |
return mNormalDelegate.taskExists(); |
||||||
} |
} |
||||||
|
|
||||||
@Override public int getTargetType() { |
@Override public int getTargetType() { |
||||||
return HTTP; |
return U_HTTP; |
||||||
} |
} |
||||||
} |
} |
||||||
|
Loading…
Reference in new issue