parent
36c226702d
commit
6f53235807
@ -0,0 +1,95 @@ |
||||
///*
|
||||
// * 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.ftp.download;
|
||||
//
|
||||
//import com.arialyy.aria.core.TaskRecord;
|
||||
//import com.arialyy.aria.core.common.SubThreadConfig;
|
||||
//import com.arialyy.aria.core.listener.IEventListener;
|
||||
//import com.arialyy.aria.core.loader.NormalTTBuilder;
|
||||
//import com.arialyy.aria.core.loader.IRecordHandler;
|
||||
//import com.arialyy.aria.core.loader.IThreadTaskBuilder;
|
||||
//import com.arialyy.aria.core.loader.NormalLoader;
|
||||
//import com.arialyy.aria.core.wrapper.AbsTaskWrapper;
|
||||
//import com.arialyy.aria.util.ALog;
|
||||
//import com.arialyy.aria.util.FileUtil;
|
||||
//import java.io.File;
|
||||
//import java.lang.reflect.InvocationHandler;
|
||||
//import java.lang.reflect.Method;
|
||||
//import java.lang.reflect.Proxy;
|
||||
//
|
||||
//final class FtpDLoader extends NormalLoader {
|
||||
// FtpDLoader(AbsTaskWrapper wrapper, IEventListener listener) {
|
||||
// super(wrapper, listener);
|
||||
// }
|
||||
//
|
||||
// @Override public void addComponent(IThreadTaskBuilder builder) {
|
||||
// mTTBuilder = (IThreadTaskBuilder) Proxy.newProxyInstance(getClass().getClassLoader(),
|
||||
// NormalTTBuilder.class.getInterfaces(), new InvocationHandler() {
|
||||
// NormalTTBuilder target = new NormalTTBuilder(mTaskWrapper);
|
||||
// @Override public Object invoke(Object proxy, Method method, Object[] args)
|
||||
// throws Exception {
|
||||
// if (method.getDeclaringClass() == Object.class) {
|
||||
// return method.invoke(this, args);
|
||||
// }
|
||||
//
|
||||
// //if (method.isDefault()) {
|
||||
// // Constructor<MethodHandles.Lookup>
|
||||
// // constructor =
|
||||
// // MethodHandles.Lookup.class.getDeclaredConstructor(Class.class, int.class);
|
||||
// // constructor.setAccessible(true);
|
||||
// // return constructor.newInstance(AbsNormalTTBuilder.class, -1 /* trusted */)
|
||||
// // .unreflectSpecial(method, AbsNormalTTBuilder.class)
|
||||
// // .bindTo(proxy)
|
||||
// // .invokeWithArguments(args);
|
||||
// //}
|
||||
//
|
||||
// String methodName = method.getName();
|
||||
// switch (methodName) {
|
||||
//
|
||||
// case "handleNewTask":
|
||||
// return handleNewTask((TaskRecord) args[0], (int) args[1]);
|
||||
// case "getAdapter":
|
||||
// return new FtpDThreadTaskAdapter((SubThreadConfig) args[0]);
|
||||
// }
|
||||
//
|
||||
// return method.invoke(target, args);
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 处理新任务
|
||||
// */
|
||||
// private boolean handleNewTask(TaskRecord record, int totalThreadNum) {
|
||||
// File temp = new File(getEntity().getFilePath());
|
||||
// if (!record.isBlock) {
|
||||
// if (temp.exists()) {
|
||||
// FileUtil.deleteFile(temp);
|
||||
// }
|
||||
// //CommonUtil.createFile(mTempFile.getPath());
|
||||
// } else {
|
||||
// for (int i = 0; i < totalThreadNum; i++) {
|
||||
// File blockFile =
|
||||
// new File(String.format(IRecordHandler.SUB_PATH, temp.getPath(), i));
|
||||
// if (blockFile.exists()) {
|
||||
// ALog.d(TAG, String.format("分块【%s】已经存在,将删除该分块", i));
|
||||
// FileUtil.deleteFile(blockFile);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// return true;
|
||||
// }
|
||||
//}
|
@ -1,41 +0,0 @@ |
||||
/* |
||||
* 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.ftp.upload; |
||||
|
||||
import com.arialyy.aria.core.TaskRecord; |
||||
import com.arialyy.aria.core.common.SubThreadConfig; |
||||
import com.arialyy.aria.core.loader.AbsNormalTTBuilder; |
||||
import com.arialyy.aria.core.task.IThreadTaskAdapter; |
||||
import com.arialyy.aria.core.wrapper.AbsTaskWrapper; |
||||
|
||||
/** |
||||
* @Author lyy |
||||
* @Date 2019-09-19 |
||||
*/ |
||||
final class FtpUTTBuilder extends AbsNormalTTBuilder { |
||||
|
||||
FtpUTTBuilder(AbsTaskWrapper wrapper) { |
||||
super(wrapper); |
||||
} |
||||
|
||||
@Override public IThreadTaskAdapter getAdapter(SubThreadConfig config) { |
||||
return new FtpUThreadTaskAdapter(config); |
||||
} |
||||
|
||||
@Override public boolean handleNewTask(TaskRecord record, int totalThreadNum) { |
||||
return true; |
||||
} |
||||
} |
@ -1,41 +0,0 @@ |
||||
/* |
||||
* 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.http.upload; |
||||
|
||||
import com.arialyy.aria.core.TaskRecord; |
||||
import com.arialyy.aria.core.common.SubThreadConfig; |
||||
import com.arialyy.aria.core.loader.AbsNormalTTBuilder; |
||||
import com.arialyy.aria.core.task.IThreadTaskAdapter; |
||||
import com.arialyy.aria.core.wrapper.AbsTaskWrapper; |
||||
|
||||
/** |
||||
* @Author lyy |
||||
* @Date 2019-09-19 |
||||
*/ |
||||
final class HttpUTTBuilder extends AbsNormalTTBuilder { |
||||
|
||||
HttpUTTBuilder(AbsTaskWrapper wrapper) { |
||||
super(wrapper); |
||||
} |
||||
|
||||
@Override public IThreadTaskAdapter getAdapter(SubThreadConfig config) { |
||||
return new HttpUThreadTaskAdapter(config); |
||||
} |
||||
|
||||
@Override public boolean handleNewTask(TaskRecord record, int totalThreadNum) { |
||||
return true; |
||||
} |
||||
} |
@ -0,0 +1,47 @@ |
||||
/* |
||||
* 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; |
||||
|
||||
/** |
||||
* 证书信息 |
||||
*/ |
||||
public class IdEntity { |
||||
|
||||
/** |
||||
* 私钥证书内容(非路径) |
||||
*/ |
||||
public String prvKey; |
||||
|
||||
/** |
||||
* 私钥证书密码 |
||||
*/ |
||||
public String prvPass; |
||||
|
||||
/** |
||||
* 公钥证书内容(非路径) |
||||
*/ |
||||
public String pubKey; |
||||
|
||||
/** |
||||
* 私钥证书路径 |
||||
*/ |
||||
public String storePath; |
||||
|
||||
/** |
||||
* 私钥别名 |
||||
*/ |
||||
public String keyAlias; |
||||
} |
@ -0,0 +1,90 @@ |
||||
/* |
||||
* 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.loader; |
||||
|
||||
import android.os.Handler; |
||||
import com.arialyy.aria.core.TaskRecord; |
||||
import com.arialyy.aria.core.ThreadRecord; |
||||
import com.arialyy.aria.core.common.AbsNormalEntity; |
||||
import com.arialyy.aria.core.common.SubThreadConfig; |
||||
import com.arialyy.aria.core.task.IThreadTaskAdapter; |
||||
import com.arialyy.aria.core.wrapper.AbsTaskWrapper; |
||||
import com.arialyy.aria.util.CommonUtil; |
||||
import java.io.File; |
||||
|
||||
public abstract class AbsNormalTTBuilderAdapter { |
||||
protected String TAG = CommonUtil.getClassName(this); |
||||
protected AbsTaskWrapper wrapper; |
||||
private File tempFile; |
||||
|
||||
public AbsNormalTTBuilderAdapter() { |
||||
} |
||||
|
||||
protected void setWrapper(AbsTaskWrapper wrapper) { |
||||
this.wrapper = wrapper; |
||||
tempFile = new File(((AbsNormalEntity) wrapper.getEntity()).getFilePath()); |
||||
} |
||||
|
||||
/** |
||||
* 创建线程任务适配器 |
||||
*/ |
||||
public abstract IThreadTaskAdapter getAdapter(SubThreadConfig config); |
||||
|
||||
/** |
||||
* 处理新任务 |
||||
* |
||||
* @param record 任务记录 |
||||
* @param totalThreadNum 任务的线程总数 |
||||
* @return {@code true}创建新任务成功 |
||||
*/ |
||||
public abstract boolean handleNewTask(TaskRecord record, int totalThreadNum); |
||||
|
||||
/** |
||||
* SubThreadConfig 模版,如果不使用该方法创建配置,则默认使用{@link #createNormalSubThreadConfig(Handler, ThreadRecord, |
||||
* boolean, int)}创建配置 |
||||
*/ |
||||
protected SubThreadConfig getSubThreadConfig(Handler stateHandler, ThreadRecord threadRecord, |
||||
boolean isBlock, int startNum) { |
||||
return createNormalSubThreadConfig(stateHandler, threadRecord, isBlock, startNum); |
||||
} |
||||
|
||||
private SubThreadConfig createNormalSubThreadConfig(Handler stateHandler, |
||||
ThreadRecord threadRecord, |
||||
boolean isBlock, int startNum) { |
||||
SubThreadConfig config = new SubThreadConfig(); |
||||
config.url = getEntity().isRedirect() ? getEntity().getRedirectUrl() : getEntity().getUrl(); |
||||
config.tempFile = |
||||
isBlock ? new File( |
||||
String.format(IRecordHandler.SUB_PATH, tempFile.getPath(), threadRecord.threadId)) |
||||
: tempFile; |
||||
config.isBlock = isBlock; |
||||
config.startThreadNum = startNum; |
||||
config.taskWrapper = wrapper; |
||||
config.record = threadRecord; |
||||
config.stateHandler = stateHandler; |
||||
config.threadType = SubThreadConfig.getThreadType(wrapper.getRequestType()); |
||||
config.updateInterval = SubThreadConfig.getUpdateInterval(wrapper.getRequestType()); |
||||
return config; |
||||
} |
||||
|
||||
protected AbsNormalEntity getEntity() { |
||||
return (AbsNormalEntity) wrapper.getEntity(); |
||||
} |
||||
|
||||
protected File getTempFile() { |
||||
return tempFile; |
||||
} |
||||
} |
@ -0,0 +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.sftp; |
||||
|
||||
import android.text.TextUtils; |
||||
import com.arialyy.aria.core.FtpUrlEntity; |
||||
import com.arialyy.aria.core.IdEntity; |
||||
import com.arialyy.aria.core.loader.IInfoTask; |
||||
import com.arialyy.aria.core.loader.ILoaderVisitor; |
||||
import com.arialyy.aria.core.wrapper.AbsTaskWrapper; |
||||
import com.arialyy.aria.exception.BaseException; |
||||
import com.arialyy.aria.ftp.FtpTaskOption; |
||||
import com.arialyy.aria.util.CommonUtil; |
||||
import com.jcraft.jsch.JSch; |
||||
import com.jcraft.jsch.JSchException; |
||||
import com.jcraft.jsch.Session; |
||||
import com.jcraft.jsch.SftpException; |
||||
import java.io.UnsupportedEncodingException; |
||||
import java.util.Properties; |
||||
|
||||
/** |
||||
* 进行登录,获取session,获取文件信息 |
||||
*/ |
||||
public abstract class AbsSFtpInfoTask<WP extends AbsTaskWrapper> implements IInfoTask { |
||||
protected String TAG = CommonUtil.getClassName(this); |
||||
protected Callback callback; |
||||
private WP wrapper; |
||||
private FtpTaskOption option; |
||||
|
||||
public AbsSFtpInfoTask(WP wp) { |
||||
this.wrapper = wp; |
||||
this.option = (FtpTaskOption) wrapper.getTaskOption(); |
||||
} |
||||
|
||||
protected abstract void getFileInfo(Session session) |
||||
throws JSchException, UnsupportedEncodingException, SftpException; |
||||
|
||||
@Override public void run() { |
||||
try { |
||||
FtpUrlEntity entity = option.getUrlEntity(); |
||||
String key = CommonUtil.getStrMd5(entity.hostName + entity.port + entity.user); |
||||
Session session = SFtpSessionManager.getInstance().getSession(key); |
||||
if (session == null) { |
||||
session = login(entity); |
||||
} |
||||
getFileInfo(session); |
||||
} catch (JSchException e) { |
||||
e.printStackTrace(); |
||||
fail(false, null); |
||||
} catch (UnsupportedEncodingException e) { |
||||
e.printStackTrace(); |
||||
fail(false, null); |
||||
} catch (SftpException e) { |
||||
e.printStackTrace(); |
||||
fail(false, null); |
||||
} |
||||
} |
||||
|
||||
private Session login(FtpUrlEntity entity) throws JSchException, UnsupportedEncodingException { |
||||
JSch jSch = new JSch(); |
||||
|
||||
IdEntity idEntity = entity.idEntity; |
||||
|
||||
if (idEntity.prvKey != null) { |
||||
if (idEntity.pubKey == null) { |
||||
jSch.addIdentity(idEntity.prvKey, |
||||
entity.password == null ? null : entity.password.getBytes("UTF-8")); |
||||
} else { |
||||
jSch.addIdentity(idEntity.prvKey, idEntity.pubKey, |
||||
entity.password == null ? null : entity.password.getBytes("UTF-8")); |
||||
} |
||||
} |
||||
|
||||
Session session; |
||||
if (TextUtils.isEmpty(entity.user)) { |
||||
session = jSch.getSession(entity.url, entity.hostName, Integer.parseInt(entity.port)); |
||||
} else { |
||||
session = jSch.getSession(entity.hostName); |
||||
} |
||||
if (!TextUtils.isEmpty(entity.password)) { |
||||
session.setPassword(entity.password); |
||||
} |
||||
Properties config = new Properties(); |
||||
config.put("StrictHostKeyChecking", "no"); |
||||
session.setConfig(config);// 为Session对象设置properties
|
||||
session.setTimeout(3000);// 设置超时
|
||||
session.setIdentityRepository(jSch.getIdentityRepository()); |
||||
session.connect(); |
||||
return session; |
||||
} |
||||
|
||||
protected FtpTaskOption getOption() { |
||||
return option; |
||||
} |
||||
|
||||
protected WP getWrapper() { |
||||
return wrapper; |
||||
} |
||||
|
||||
protected void fail(boolean needRetry, BaseException e) { |
||||
callback.onFail(getWrapper().getEntity(), e, needRetry); |
||||
} |
||||
|
||||
@Override public void setCallback(Callback callback) { |
||||
this.callback = callback; |
||||
} |
||||
|
||||
@Override public void accept(ILoaderVisitor visitor) { |
||||
visitor.addComponent(this); |
||||
} |
||||
} |
@ -1,100 +0,0 @@ |
||||
///*
|
||||
// * 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.sftp;
|
||||
//
|
||||
//import com.arialyy.aria.core.AriaConfig;
|
||||
//import com.arialyy.aria.core.FtpUrlEntity;
|
||||
//import com.arialyy.aria.core.common.AbsNormalEntity;
|
||||
//import com.arialyy.aria.core.inf.OnFileInfoCallback;
|
||||
//import com.arialyy.aria.core.upload.UploadEntity;
|
||||
//import com.arialyy.aria.core.wrapper.AbsTaskWrapper;
|
||||
//import com.arialyy.aria.ftp.FtpTaskOption;
|
||||
//import com.arialyy.aria.util.ALog;
|
||||
//import com.arialyy.aria.util.CommonUtil;
|
||||
//import com.jcraft.jsch.ChannelSftp;
|
||||
//import com.jcraft.jsch.JSchException;
|
||||
//import com.jcraft.jsch.SftpException;
|
||||
//import java.util.Vector;
|
||||
//
|
||||
///**
|
||||
// * https://cloud.tencent.com/developer/article/1354612
|
||||
// *
|
||||
// * @author lyy
|
||||
// */
|
||||
//public class SFtpInfoThread<ENTITY extends AbsNormalEntity, TASK_WRAPPER extends AbsTaskWrapper<ENTITY>>
|
||||
// implements Runnable {
|
||||
//
|
||||
// private final String TAG = CommonUtil.getClassName(getClass());
|
||||
// protected ENTITY mEntity;
|
||||
// protected TASK_WRAPPER mTaskWrapper;
|
||||
// protected FtpTaskOption mTaskOption;
|
||||
// private int mConnectTimeOut;
|
||||
// protected OnFileInfoCallback mCallback;
|
||||
// protected long mSize = 0;
|
||||
// protected String charSet = "UTF-8";
|
||||
// private boolean isUpload = false;
|
||||
// private SFtpUtil mSFtpUtil;
|
||||
// private BaseInfoThreadAdapter mAdapter;
|
||||
//
|
||||
// public SFtpInfoThread(SFtpUtil ftpUtil, TASK_WRAPPER taskWrapper,
|
||||
// OnFileInfoCallback callback) {
|
||||
// mSFtpUtil = ftpUtil;
|
||||
// mTaskWrapper = taskWrapper;
|
||||
// mEntity = taskWrapper.getEntity();
|
||||
// mTaskOption = (FtpTaskOption) taskWrapper.getTaskOption();
|
||||
// mConnectTimeOut = AriaConfig.getInstance().getDConfig().getConnectTimeOut();
|
||||
// mCallback = callback;
|
||||
// if (mEntity instanceof UploadEntity) {
|
||||
// isUpload = true;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// public void setAdapter(BaseInfoThreadAdapter adapter) {
|
||||
// mAdapter = adapter;
|
||||
// }
|
||||
//
|
||||
// @Override public void run() {
|
||||
// if (mAdapter == null) {
|
||||
// ALog.e(TAG, "adapter为空");
|
||||
// return;
|
||||
// }
|
||||
// try {
|
||||
// ChannelSftp channelSftp =
|
||||
// (ChannelSftp) mSFtpUtil.getSession().openChannel(SFtpUtil.CMD_TYPE_SFTP);
|
||||
// Vector files = channelSftp.ls(getUrlEntity().remotePath);
|
||||
//
|
||||
// if (files.isEmpty()) {
|
||||
// ALog.e(TAG, String.format("路径【%s】没有文件", getUrlEntity().remotePath));
|
||||
// mCallback.onFail(mEntity, null, false);
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// if (!mAdapter.handlerFile(files)) {
|
||||
// ALog.e(TAG, "文件处理失败");
|
||||
// mCallback.onFail(mEntity, null, false);
|
||||
// return;
|
||||
// }
|
||||
// } catch (JSchException ex) {
|
||||
// ex.printStackTrace();
|
||||
// } catch (SftpException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// private FtpUrlEntity getUrlEntity() {
|
||||
// return mTaskOption.getUrlEntity();
|
||||
// }
|
||||
//}
|
@ -0,0 +1,98 @@ |
||||
/* |
||||
* 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.sftp; |
||||
|
||||
import android.text.TextUtils; |
||||
import com.arialyy.aria.util.ALog; |
||||
import com.arialyy.aria.util.CommonUtil; |
||||
import com.jcraft.jsch.Session; |
||||
import java.util.HashMap; |
||||
import java.util.Iterator; |
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* SFTP session 管理器 |
||||
* 1、管理session |
||||
* 2、定时清除无效的session |
||||
*/ |
||||
public class SFtpSessionManager { |
||||
private String TAG = CommonUtil.getClassName(this); |
||||
private static volatile SFtpSessionManager INSTANCE = null; |
||||
private Map<String, Session> sessionDeque = new HashMap<>(); |
||||
|
||||
public synchronized static SFtpSessionManager getInstance() { |
||||
if (INSTANCE == null) { |
||||
synchronized (SFtpSessionManager.class) { |
||||
INSTANCE = new SFtpSessionManager(); |
||||
} |
||||
} |
||||
return INSTANCE; |
||||
} |
||||
|
||||
private SFtpSessionManager() { |
||||
|
||||
} |
||||
|
||||
/** |
||||
* 获取session,获取完成session后,检查map中的所有session,移除所有失效的session |
||||
* |
||||
* @param key md5(host + port + userName ) |
||||
* @return 如果session不可用,返回null |
||||
*/ |
||||
public Session getSession(String key) { |
||||
if (TextUtils.isEmpty(key)) { |
||||
ALog.e(TAG, "获取session失败,key为空"); |
||||
return null; |
||||
} |
||||
Session session = sessionDeque.get(key); |
||||
if (session == null) { |
||||
ALog.w(TAG, "获取session失败,key:" + key); |
||||
} |
||||
cleanIdleSession(); |
||||
return session; |
||||
} |
||||
|
||||
/** |
||||
* 添加session |
||||
*/ |
||||
public void addSession(Session session) { |
||||
if (session == null) { |
||||
ALog.e(TAG, "添加session到管理器失败,session 为空"); |
||||
return; |
||||
} |
||||
String key = |
||||
CommonUtil.getStrMd5(session.getHost() + session.getPort() + session.getUserName()); |
||||
sessionDeque.put(key, session); |
||||
} |
||||
|
||||
/** |
||||
* 移除所有闲置的session,闲置条件: |
||||
* 1、session 为空 |
||||
* 2、session未连接 |
||||
*/ |
||||
private void cleanIdleSession() { |
||||
if (sessionDeque.size() > 0) { |
||||
Iterator<Map.Entry<String, Session>> i = sessionDeque.entrySet().iterator(); |
||||
while (i.hasNext()) { |
||||
Map.Entry<String, Session> entry = i.next(); |
||||
Session session = entry.getValue(); |
||||
if (session == null || !session.isConnected()) { |
||||
i.remove(); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,49 @@ |
||||
/* |
||||
* 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.sftp.download; |
||||
|
||||
import com.arialyy.aria.core.common.CompleteInfo; |
||||
import com.arialyy.aria.core.download.DTaskWrapper; |
||||
import com.arialyy.aria.sftp.AbsSFtpInfoTask; |
||||
import com.arialyy.aria.util.CommonUtil; |
||||
import com.jcraft.jsch.ChannelSftp; |
||||
import com.jcraft.jsch.JSchException; |
||||
import com.jcraft.jsch.Session; |
||||
import com.jcraft.jsch.SftpATTRS; |
||||
import com.jcraft.jsch.SftpException; |
||||
import java.io.UnsupportedEncodingException; |
||||
|
||||
/** |
||||
* 进行登录,获取session,获取文件信息 |
||||
*/ |
||||
final class SFtpDInfoTask extends AbsSFtpInfoTask<DTaskWrapper> { |
||||
|
||||
SFtpDInfoTask(DTaskWrapper wrapper) { |
||||
super(wrapper); |
||||
} |
||||
|
||||
@Override protected void getFileInfo(Session session) throws JSchException, |
||||
UnsupportedEncodingException, SftpException { |
||||
ChannelSftp channel = (ChannelSftp) session.openChannel("sftp"); |
||||
SftpATTRS attr = channel.stat( |
||||
CommonUtil.convertFtpChar(getOption().getCharSet(), getWrapper().getEntity().getUrl())); |
||||
getWrapper().getEntity().setFileSize(attr.getSize()); |
||||
CompleteInfo info = new CompleteInfo(); |
||||
info.code = 200; |
||||
info.obj = channel; |
||||
callback.onSucceed(getWrapper().getKey(), info); |
||||
} |
||||
} |
@ -0,0 +1,163 @@ |
||||
/* |
||||
* 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.sftp.download; |
||||
|
||||
import android.os.Handler; |
||||
import android.os.Looper; |
||||
import com.arialyy.aria.core.common.AbsEntity; |
||||
import com.arialyy.aria.core.common.AbsNormalEntity; |
||||
import com.arialyy.aria.core.common.CompleteInfo; |
||||
import com.arialyy.aria.core.event.EventMsgUtil; |
||||
import com.arialyy.aria.core.inf.IThreadStateManager; |
||||
import com.arialyy.aria.core.listener.IDLoadListener; |
||||
import com.arialyy.aria.core.listener.IEventListener; |
||||
import com.arialyy.aria.core.loader.AbsNormalLoader; |
||||
import com.arialyy.aria.core.loader.IInfoTask; |
||||
import com.arialyy.aria.core.loader.IRecordHandler; |
||||
import com.arialyy.aria.core.loader.IThreadTaskBuilder; |
||||
import com.arialyy.aria.core.loader.NormalTTBuilder; |
||||
import com.arialyy.aria.core.manager.ThreadTaskManager; |
||||
import com.arialyy.aria.core.task.IThreadTask; |
||||
import com.arialyy.aria.core.wrapper.AbsTaskWrapper; |
||||
import com.arialyy.aria.exception.BaseException; |
||||
import com.arialyy.aria.util.FileUtil; |
||||
import com.jcraft.jsch.ChannelSftp; |
||||
import java.io.File; |
||||
|
||||
final class SFtpDLoader extends AbsNormalLoader { |
||||
|
||||
private int startThreadNum; //启动的线程数
|
||||
private boolean isComplete = false; |
||||
private Looper looper; |
||||
private ChannelSftp channelSftp; |
||||
|
||||
SFtpDLoader(AbsTaskWrapper wrapper, IEventListener listener) { |
||||
super(wrapper, listener); |
||||
mTempFile = new File(getEntity().getFilePath()); |
||||
EventMsgUtil.getDefault().register(this); |
||||
setUpdateInterval(wrapper.getConfig().getUpdateInterval()); |
||||
} |
||||
|
||||
private AbsNormalEntity getEntity() { |
||||
return (AbsNormalEntity) mTaskWrapper.getEntity(); |
||||
} |
||||
|
||||
@Override public long getFileSize() { |
||||
return getEntity().getFileSize(); |
||||
} |
||||
|
||||
/** |
||||
* 设置最大下载/上传速度AbsFtpInfoThread |
||||
* |
||||
* @param maxSpeed 单位为:kb |
||||
*/ |
||||
protected void setMaxSpeed(int maxSpeed) { |
||||
for (IThreadTask threadTask : getTaskList()) { |
||||
if (threadTask != null && startThreadNum > 0) { |
||||
threadTask.setMaxSpeed(maxSpeed / startThreadNum); |
||||
} |
||||
} |
||||
} |
||||
|
||||
@Override public void onDestroy() { |
||||
super.onDestroy(); |
||||
EventMsgUtil.getDefault().unRegister(this); |
||||
} |
||||
|
||||
/** |
||||
* 启动单线程任务 |
||||
*/ |
||||
@Override |
||||
public void handleTask(Looper looper) { |
||||
if (isBreak() || isComplete) { |
||||
return; |
||||
} |
||||
this.looper = looper; |
||||
mInfoTask.run(); |
||||
} |
||||
|
||||
private void startThreadTask() { |
||||
|
||||
if (getListener() instanceof IDLoadListener) { |
||||
((IDLoadListener) getListener()).onPostPre(getEntity().getFileSize()); |
||||
} |
||||
File file = new File(getEntity().getFilePath()); |
||||
if (file.getParentFile() != null && !file.getParentFile().exists()) { |
||||
FileUtil.createDir(file.getPath()); |
||||
} |
||||
// 处理记录、初始化状态管理器
|
||||
mRecord = mRecordHandler.getRecord(getFileSize()); |
||||
mStateManager.setLooper(mRecord, looper); |
||||
|
||||
// 创建线程任务
|
||||
SFtpDTTBuilderAdapter ttBuild = |
||||
(SFtpDTTBuilderAdapter) ((NormalTTBuilder) mTTBuilder).getAdapter(); |
||||
ttBuild.setChannel(channelSftp); |
||||
getTaskList().addAll(mTTBuilder.buildThreadTask(mRecord, |
||||
new Handler(looper, mStateManager.getHandlerCallback()))); |
||||
startThreadNum = mTTBuilder.getCreatedThreadNum(); |
||||
|
||||
mStateManager.updateCurrentProgress(getEntity().getCurrentProgress()); |
||||
if (mStateManager.getCurrentProgress() > 0) { |
||||
getListener().onResume(mStateManager.getCurrentProgress()); |
||||
} else { |
||||
getListener().onStart(mStateManager.getCurrentProgress()); |
||||
} |
||||
|
||||
// 启动线程任务
|
||||
for (IThreadTask threadTask : getTaskList()) { |
||||
ThreadTaskManager.getInstance().startThread(mTaskWrapper.getKey(), threadTask); |
||||
} |
||||
|
||||
// 启动定时器
|
||||
startTimer(); |
||||
} |
||||
|
||||
@Override public long getCurrentProgress() { |
||||
return isRunning() ? mStateManager.getCurrentProgress() : getEntity().getCurrentProgress(); |
||||
} |
||||
|
||||
@Override public void addComponent(IRecordHandler recordHandler) { |
||||
mRecordHandler = recordHandler; |
||||
if (recordHandler.checkTaskCompleted()) { |
||||
mRecord.deleteData(); |
||||
isComplete = true; |
||||
getListener().onComplete(); |
||||
} |
||||
} |
||||
|
||||
@Override public void addComponent(IInfoTask infoTask) { |
||||
mInfoTask = infoTask; |
||||
infoTask.setCallback(new IInfoTask.Callback() { |
||||
@Override public void onSucceed(String key, CompleteInfo info) { |
||||
channelSftp = (ChannelSftp) info.obj; |
||||
startThreadTask(); |
||||
} |
||||
|
||||
@Override public void onFail(AbsEntity entity, BaseException e, boolean needRetry) { |
||||
getListener().onFail(needRetry, e); |
||||
} |
||||
}); |
||||
} |
||||
|
||||
@Override public void addComponent(IThreadStateManager threadState) { |
||||
mStateManager = threadState; |
||||
} |
||||
|
||||
@Override public void addComponent(IThreadTaskBuilder builder) { |
||||
mTTBuilder = builder; |
||||
} |
||||
} |
@ -1,40 +0,0 @@ |
||||
///*
|
||||
// * 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.sftp.download;
|
||||
//
|
||||
//import com.arialyy.aria.core.common.SubThreadConfig;
|
||||
//import com.arialyy.aria.core.task.IThreadTask;
|
||||
//import com.arialyy.aria.core.task.ThreadTask;
|
||||
//import com.arialyy.aria.core.wrapper.ITaskWrapper;
|
||||
//import com.arialyy.aria.ftp.download.FtpDTTBuilder;
|
||||
//
|
||||
///**
|
||||
// * sftp下载适配器
|
||||
// *
|
||||
// * @author lyy
|
||||
// */
|
||||
//final class SFtpDLoaderAdapter extends FtpDTTBuilder {
|
||||
// SFtpDLoaderAdapter(ITaskWrapper wrapper) {
|
||||
// super(wrapper);
|
||||
// }
|
||||
//
|
||||
// @Override public IThreadTask createThreadTask(SubThreadConfig config) {
|
||||
// ThreadTask threadTask = new ThreadTask(config);
|
||||
// SFtpDThreadTaskAdapter adapter = new SFtpDThreadTaskAdapter(config);
|
||||
// threadTask.setAdapter(adapter);
|
||||
// return threadTask;
|
||||
// }
|
||||
//}
|
@ -1,75 +1,54 @@ |
||||
///*
|
||||
// * 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.sftp.download;
|
||||
//
|
||||
//import com.arialyy.aria.core.common.AbsEntity;
|
||||
//import com.arialyy.aria.core.common.CompleteInfo;
|
||||
//import com.arialyy.aria.core.download.DTaskWrapper;
|
||||
//import com.arialyy.aria.core.inf.OnFileInfoCallback;
|
||||
//import com.arialyy.aria.core.listener.IEventListener;
|
||||
//import com.arialyy.aria.core.loader.AbsNormalLoader;
|
||||
//import com.arialyy.aria.core.loader.AbsNormalLoaderUtil;
|
||||
//import com.arialyy.aria.core.loader.NormalLoader;
|
||||
//import com.arialyy.aria.core.wrapper.AbsTaskWrapper;
|
||||
//import com.arialyy.aria.exception.BaseException;
|
||||
//import com.arialyy.aria.ftp.FtpTaskOption;
|
||||
//import com.arialyy.aria.sftp.SFtpInfoThread;
|
||||
//import com.arialyy.aria.sftp.SFtpUtil;
|
||||
//
|
||||
///**
|
||||
// * sftp下载工具
|
||||
// *
|
||||
// * @author lyy
|
||||
// */
|
||||
//public class SFtpDLoaderUtil extends AbsNormalLoaderUtil {
|
||||
//
|
||||
// private SFtpUtil mSftpUtil;
|
||||
//
|
||||
// protected SFtpDLoaderUtil(AbsTaskWrapper wrapper, IEventListener listener) {
|
||||
// super(wrapper, listener);
|
||||
// wrapper.generateTaskOption(FtpTaskOption.class);
|
||||
// FtpTaskOption option = (FtpTaskOption) wrapper.getTaskOption();
|
||||
// mSftpUtil = new SFtpUtil.Builder()
|
||||
// .setIp(option.getUrlEntity().hostName)
|
||||
// .setPort(Integer.parseInt(option.getUrlEntity().port))
|
||||
// .setUserName(option.getUrlEntity().user)
|
||||
// .setPassword(option.getUrlEntity().password)
|
||||
// .build();
|
||||
// }
|
||||
//
|
||||
// @Override protected AbsNormalLoader createLoader() {
|
||||
// NormalLoader loader = new NormalLoader(getListener(), getTaskWrapper());
|
||||
// loader.setAdapter(new SFtpDLoaderAdapter(getTaskWrapper()));
|
||||
// return loader;
|
||||
// }
|
||||
//
|
||||
// @Override protected Runnable createInfoThread() {
|
||||
// DSFtpInfoThreadAdapter adapter = new DSFtpInfoThreadAdapter((DTaskWrapper) getTaskWrapper());
|
||||
// SFtpInfoThread infoThread = new SFtpInfoThread<>(mSftpUtil, (DTaskWrapper) getTaskWrapper(),
|
||||
// new OnFileInfoCallback() {
|
||||
// @Override public void onComplete(String key, CompleteInfo info) {
|
||||
//
|
||||
// }
|
||||
//
|
||||
// @Override public void onFail(AbsEntity entity, BaseException e, boolean needRetry) {
|
||||
//
|
||||
// }
|
||||
// });
|
||||
// infoThread.setAdapter(adapter);
|
||||
//
|
||||
// return infoThread;
|
||||
// }
|
||||
//}
|
||||
/* |
||||
* 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.sftp.download; |
||||
|
||||
import com.arialyy.aria.core.download.DTaskWrapper; |
||||
import com.arialyy.aria.core.listener.IEventListener; |
||||
import com.arialyy.aria.core.loader.AbsNormalLoader; |
||||
import com.arialyy.aria.core.loader.AbsNormalLoaderUtil; |
||||
import com.arialyy.aria.core.loader.LoaderStructure; |
||||
import com.arialyy.aria.core.loader.NormalTTBuilder; |
||||
import com.arialyy.aria.core.loader.NormalThreadStateManager; |
||||
import com.arialyy.aria.core.wrapper.AbsTaskWrapper; |
||||
import com.arialyy.aria.ftp.FtpTaskOption; |
||||
import com.arialyy.aria.ftp.download.FtpDRecordHandler; |
||||
|
||||
/** |
||||
* sftp下载工具 |
||||
* |
||||
* @author lyy |
||||
*/ |
||||
public class SFtpDLoaderUtil extends AbsNormalLoaderUtil { |
||||
|
||||
protected SFtpDLoaderUtil(AbsTaskWrapper wrapper, IEventListener listener) { |
||||
super(wrapper, listener); |
||||
wrapper.generateTaskOption(FtpTaskOption.class); |
||||
} |
||||
|
||||
@Override public AbsNormalLoader getLoader() { |
||||
return mLoader == null ? new SFtpDLoader(getTaskWrapper(), getListener()) : mLoader; |
||||
} |
||||
|
||||
@Override public LoaderStructure BuildLoaderStructure() { |
||||
LoaderStructure structure = new LoaderStructure(); |
||||
structure.addComponent(new FtpDRecordHandler((DTaskWrapper) getTaskWrapper())) |
||||
.addComponent(new NormalThreadStateManager(getListener())) |
||||
.addComponent(new SFtpDInfoTask((DTaskWrapper) getTaskWrapper())) |
||||
.addComponent(new NormalTTBuilder(getTaskWrapper(), new SFtpDTTBuilderAdapter()git)); |
||||
structure.accept(getLoader()); |
||||
return structure; |
||||
} |
||||
} |
||||
|
@ -0,0 +1,72 @@ |
||||
/* |
||||
* 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.sftp.download; |
||||
|
||||
import android.os.Handler; |
||||
import com.arialyy.aria.core.TaskRecord; |
||||
import com.arialyy.aria.core.ThreadRecord; |
||||
import com.arialyy.aria.core.common.SubThreadConfig; |
||||
import com.arialyy.aria.core.loader.AbsNormalTTBuilderAdapter; |
||||
import com.arialyy.aria.core.loader.IRecordHandler; |
||||
import com.arialyy.aria.core.task.IThreadTaskAdapter; |
||||
import com.arialyy.aria.util.ALog; |
||||
import com.arialyy.aria.util.FileUtil; |
||||
import com.jcraft.jsch.ChannelSftp; |
||||
import java.io.File; |
||||
|
||||
class SFtpDTTBuilderAdapter extends AbsNormalTTBuilderAdapter { |
||||
private ChannelSftp channel; |
||||
|
||||
SFtpDTTBuilderAdapter() { |
||||
} |
||||
|
||||
void setChannel(ChannelSftp channel) { |
||||
this.channel = channel; |
||||
} |
||||
|
||||
@Override public IThreadTaskAdapter getAdapter(SubThreadConfig config) { |
||||
return new SFtpDThreadTaskAdapter(config); |
||||
} |
||||
|
||||
@Override |
||||
protected SubThreadConfig getSubThreadConfig(Handler stateHandler, ThreadRecord threadRecord, |
||||
boolean isBlock, int startNum) { |
||||
SubThreadConfig config = |
||||
super.getSubThreadConfig(stateHandler, threadRecord, isBlock, startNum); |
||||
config.obj = channel; |
||||
|
||||
return config; |
||||
} |
||||
|
||||
@Override public boolean handleNewTask(TaskRecord record, int totalThreadNum) { |
||||
if (!record.isBlock) { |
||||
if (getTempFile().exists()) { |
||||
FileUtil.deleteFile(getTempFile()); |
||||
} |
||||
//CommonUtil.createFile(mTempFile.getPath());
|
||||
} else { |
||||
for (int i = 0; i < totalThreadNum; i++) { |
||||
File blockFile = |
||||
new File(String.format(IRecordHandler.SUB_PATH, getTempFile().getPath(), i)); |
||||
if (blockFile.exists()) { |
||||
ALog.d(TAG, String.format("分块【%s】已经存在,将删除该分块", i)); |
||||
FileUtil.deleteFile(blockFile); |
||||
} |
||||
} |
||||
} |
||||
return true; |
||||
} |
||||
} |
Loading…
Reference in new issue