pull/330/head
AriaLyy 7 years ago
parent 0960d5c6b6
commit 53128b42dd
  1. 2
      Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupTask.java
  2. 4
      Aria/src/main/java/com/arialyy/aria/core/download/DownloadTask.java
  3. 38
      Aria/src/main/java/com/arialyy/aria/core/download/downloader/ftp/FtpConfigEntity.java
  4. 36
      Aria/src/main/java/com/arialyy/aria/core/download/downloader/ftp/FtpDownloadUtil.java
  5. 96
      Aria/src/main/java/com/arialyy/aria/core/download/downloader/ftp/FtpThreadTask.java
  6. 2
      Aria/src/main/java/com/arialyy/aria/core/download/downloader/http/ChildThreadConfigEntity.java
  7. 2
      Aria/src/main/java/com/arialyy/aria/core/download/downloader/http/ConnectionHelp.java
  8. 5
      Aria/src/main/java/com/arialyy/aria/core/download/downloader/http/DownloadGroupUtil.java
  9. 7
      Aria/src/main/java/com/arialyy/aria/core/download/downloader/http/Downloader.java
  10. 2
      Aria/src/main/java/com/arialyy/aria/core/download/downloader/http/FileInfoThread.java
  11. 4
      Aria/src/main/java/com/arialyy/aria/core/download/downloader/http/SimpleDownloadUtil.java
  12. 3
      Aria/src/main/java/com/arialyy/aria/core/download/downloader/http/SingleThreadTask.java
  13. 2
      Aria/src/main/java/com/arialyy/aria/core/download/downloader/http/StateConstance.java

@ -17,7 +17,7 @@ package com.arialyy.aria.core.download;
import android.os.Handler; import android.os.Handler;
import com.arialyy.aria.core.AriaManager; import com.arialyy.aria.core.AriaManager;
import com.arialyy.aria.core.download.downloader.DownloadGroupUtil; import com.arialyy.aria.core.download.downloader.http.DownloadGroupUtil;
import com.arialyy.aria.core.download.downloader.IDownloadUtil; import com.arialyy.aria.core.download.downloader.IDownloadUtil;
import com.arialyy.aria.core.inf.AbsGroupTask; import com.arialyy.aria.core.inf.AbsGroupTask;
import com.arialyy.aria.core.scheduler.ISchedulers; import com.arialyy.aria.core.scheduler.ISchedulers;

@ -19,9 +19,9 @@ package com.arialyy.aria.core.download;
import android.os.Handler; import android.os.Handler;
import android.util.Log; import android.util.Log;
import com.arialyy.aria.core.AriaManager; import com.arialyy.aria.core.AriaManager;
import com.arialyy.aria.core.download.downloader.FtpDownloadUtil; import com.arialyy.aria.core.download.downloader.ftp.FtpDownloadUtil;
import com.arialyy.aria.core.download.downloader.IDownloadUtil; import com.arialyy.aria.core.download.downloader.IDownloadUtil;
import com.arialyy.aria.core.download.downloader.SimpleDownloadUtil; import com.arialyy.aria.core.download.downloader.http.SimpleDownloadUtil;
import com.arialyy.aria.core.inf.AbsNormalTask; import com.arialyy.aria.core.inf.AbsNormalTask;
import com.arialyy.aria.core.inf.AbsTaskEntity; import com.arialyy.aria.core.inf.AbsTaskEntity;
import com.arialyy.aria.core.inf.IEntity; import com.arialyy.aria.core.inf.IEntity;

@ -0,0 +1,38 @@
/*
* 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.downloader.ftp;
import com.arialyy.aria.core.download.DownloadTaskEntity;
/**
* Created by Aria.Lao on 2017/7/24.
* ftp下载信息实体
*/
class FtpConfigEntity {
//下载文件大小
long FILE_SIZE;
//子线程启动下载位置
long START_LOCATION;
//下载路径
String PATH;
DownloadTaskEntity TASK_ENTITY;
//FTP 服务器地址
String SERVER_IP;
//FTP 服务器端口
String PORT;
//FTP服务器地址
String SERVER_FILE_PATH;
}

@ -1,9 +1,34 @@
package com.arialyy.aria.core.download.downloader; /*
* 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.downloader.ftp;
import com.arialyy.aria.core.download.DownloadEntity; import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.download.DownloadTaskEntity; import com.arialyy.aria.core.download.DownloadTaskEntity;
import com.arialyy.aria.core.download.downloader.IDownloadListener;
import com.arialyy.aria.core.download.downloader.IDownloadUtil;
import com.arialyy.aria.util.BufferedRandomAccessFile;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import org.apache.commons.net.ftp.FTP;
import org.apache.commons.net.ftp.FTPClient; import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPFile;
import org.apache.commons.net.ftp.FTPFileEntryParser;
import org.apache.commons.net.ftp.FTPListParseEngine;
import org.apache.commons.net.ftp.FTPReply; import org.apache.commons.net.ftp.FTPReply;
/** /**
@ -63,15 +88,6 @@ public class FtpDownloadUtil implements IDownloadUtil, Runnable {
} }
private void test() throws IOException { private void test() throws IOException {
FTPClient client = new FTPClient();
client.connect(mEntity.getDownloadUrl());
client.login(mTaskEntity.userName, mTaskEntity.userPw);
int reply = client.getReplyCode();
if (!FTPReply.isPositiveCompletion(reply)) {
client.disconnect();
failDownload("无法连接到ftp服务器,错误码为:" + reply);
return;
}
} }
} }

@ -0,0 +1,96 @@
///*
// * 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.downloader.ftp;
//
//import com.arialyy.aria.core.AriaManager;
//import com.arialyy.aria.core.download.DownloadTaskEntity;
//import com.arialyy.aria.core.download.downloader.IDownloadListener;
//import com.arialyy.aria.util.BufferedRandomAccessFile;
//import java.io.File;
//import java.io.IOException;
//import java.io.InputStream;
//import java.math.BigDecimal;
//import org.apache.commons.net.ftp.FTP;
//import org.apache.commons.net.ftp.FTPClient;
//import org.apache.commons.net.ftp.FTPFile;
//import org.apache.commons.net.ftp.FTPReply;
//
///**
// * Created by Aria.Lao on 2017/7/24.
// * Ftp下载任务
// */
//class FtpThreadTask implements Runnable {
//
// private FtpConfigEntity mConfig;
// private IDownloadListener mListener;
// private DownloadTaskEntity mTaskEntity;
// private int mBufSize;
// private long mSleepTime = 0;
//
// FtpThreadTask(FtpConfigEntity config, IDownloadListener listener) {
// AriaManager manager = AriaManager.getInstance(AriaManager.APP);
// mConfig = config;
// mListener = listener;
//
// mBufSize = manager.getDownloadConfig().getBuffSize();
// setMaxSpeed(AriaManager.getInstance(AriaManager.APP).getDownloadConfig().getMsxSpeed());
// }
//
// void setMaxSpeed(double maxSpeed) {
// if (-0.9999 < maxSpeed && maxSpeed < 0.00001) {
// mSleepTime = 0;
// } else {
// BigDecimal db = new BigDecimal(((mBufSize / 1024) / maxSpeed) * 1000);
// mSleepTime = db.setScale(0, BigDecimal.ROUND_HALF_UP).longValue();
// }
// }
//
// @Override public void run() {
// try {
//
// FTPClient client = new FTPClient();
// //ip和端口
// //String[] temp = mEntity.getDownloadUrl().split("/");
// //String[] pp = temp[2].split(":");
// String dir = temp[temp.length - 2];
// String fileName = temp[temp.length - 1];
// client.connect(pp[0], Integer.parseInt(pp[1]));
// client.login(mTaskEntity.userName, mTaskEntity.userPw);
// int reply = client.getReplyCode();
// if (!FTPReply.isPositiveCompletion(reply)) {
// client.disconnect();
// //failDownload("无法连接到ftp服务器,错误码为:" + reply);
// return;
// }
// client.enterLocalPassiveMode();
// client.setFileType(FTP.BINARY_FILE_TYPE);
// FTPFile[] files = client.listFiles(fileName);
// files[0].getSize();
// BufferedRandomAccessFile file =
// new BufferedRandomAccessFile(new File(mConfig.PATH), "rwd", 8192);
// InputStream is = client.retrieveFileStream(fileName);
//
// byte[] buffer = new byte[8192];
// int len;
// //当前子线程的下载位置
// while ((len = is.read(buffer)) != -1) {
// file.write(buffer, 0, len);
// }
// }catch (IOException e){
//
// }
// }
//}

@ -1,4 +1,4 @@
package com.arialyy.aria.core.download.downloader; package com.arialyy.aria.core.download.downloader.http;
import com.arialyy.aria.core.download.DownloadTaskEntity; import com.arialyy.aria.core.download.DownloadTaskEntity;
import java.io.File; import java.io.File;

@ -13,7 +13,7 @@
* 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.downloader; package com.arialyy.aria.core.download.downloader.http;
import com.arialyy.aria.core.download.DownloadTaskEntity; import com.arialyy.aria.core.download.DownloadTaskEntity;
import com.arialyy.aria.util.SSLContextUtil; import com.arialyy.aria.util.SSLContextUtil;

@ -13,12 +13,15 @@
* 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.downloader; package com.arialyy.aria.core.download.downloader.http;
import android.util.SparseArray; import android.util.SparseArray;
import com.arialyy.aria.core.download.DownloadEntity; import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.download.DownloadGroupTaskEntity; import com.arialyy.aria.core.download.DownloadGroupTaskEntity;
import com.arialyy.aria.core.download.DownloadTaskEntity; import com.arialyy.aria.core.download.DownloadTaskEntity;
import com.arialyy.aria.core.download.downloader.IDownloadGroupListener;
import com.arialyy.aria.core.download.downloader.IDownloadListener;
import com.arialyy.aria.core.download.downloader.IDownloadUtil;
import com.arialyy.aria.core.inf.IEntity; import com.arialyy.aria.core.inf.IEntity;
import com.arialyy.aria.orm.DbEntity; import com.arialyy.aria.orm.DbEntity;
import com.arialyy.aria.util.CommonUtil; import com.arialyy.aria.util.CommonUtil;

@ -13,7 +13,7 @@
* 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.downloader; package com.arialyy.aria.core.download.downloader.http;
import android.content.Context; import android.content.Context;
import android.util.Log; import android.util.Log;
@ -21,6 +21,8 @@ import android.util.SparseArray;
import com.arialyy.aria.core.AriaManager; import com.arialyy.aria.core.AriaManager;
import com.arialyy.aria.core.download.DownloadEntity; import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.download.DownloadTaskEntity; import com.arialyy.aria.core.download.DownloadTaskEntity;
import com.arialyy.aria.core.download.downloader.IDownloadListener;
import com.arialyy.aria.core.download.downloader.IDownloadUtil;
import com.arialyy.aria.orm.DbEntity; import com.arialyy.aria.orm.DbEntity;
import com.arialyy.aria.util.BufferedRandomAccessFile; import com.arialyy.aria.util.BufferedRandomAccessFile;
import com.arialyy.aria.util.CommonUtil; import com.arialyy.aria.util.CommonUtil;
@ -65,7 +67,8 @@ class Downloader implements Runnable, IDownloadUtil {
mConstance = new StateConstance(); mConstance = new StateConstance();
} }
void setMaxSpeed(double maxSpeed) { @Override
public void setMaxSpeed(double maxSpeed) {
for (int i = 0; i < mThreadNum; i++) { for (int i = 0; i < mThreadNum; i++) {
SingleThreadTask task = (SingleThreadTask) mTask.get(i); SingleThreadTask task = (SingleThreadTask) mTask.get(i);
if (task != null) { if (task != null) {

@ -13,7 +13,7 @@
* 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.downloader; package com.arialyy.aria.core.download.downloader.http;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log; import android.util.Log;

@ -14,11 +14,13 @@
* limitations under the License. * limitations under the License.
*/ */
package com.arialyy.aria.core.download.downloader; package com.arialyy.aria.core.download.downloader.http;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log; import android.util.Log;
import com.arialyy.aria.core.download.DownloadTaskEntity; import com.arialyy.aria.core.download.DownloadTaskEntity;
import com.arialyy.aria.core.download.downloader.IDownloadListener;
import com.arialyy.aria.core.download.downloader.IDownloadUtil;
/** /**
* Created by lyy on 2015/8/25. * Created by lyy on 2015/8/25.

@ -13,12 +13,13 @@
* 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.downloader; package com.arialyy.aria.core.download.downloader.http;
import android.os.Build; import android.os.Build;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log; import android.util.Log;
import com.arialyy.aria.core.AriaManager; import com.arialyy.aria.core.AriaManager;
import com.arialyy.aria.core.download.downloader.IDownloadListener;
import com.arialyy.aria.util.BufferedRandomAccessFile; import com.arialyy.aria.util.BufferedRandomAccessFile;
import com.arialyy.aria.util.CommonUtil; import com.arialyy.aria.util.CommonUtil;
import java.io.File; import java.io.File;

@ -13,7 +13,7 @@
* 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.downloader; package com.arialyy.aria.core.download.downloader.http;
/** /**
* Created by lyy on 2017/1/18. * Created by lyy on 2017/1/18.
Loading…
Cancel
Save