├── .gitignore ├── ClassicDownload ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── zero │ │ └── cdownload │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── zero │ │ │ └── cdownload │ │ │ ├── CDownload.java │ │ │ ├── config │ │ │ ├── CDownloadConfig.java │ │ │ ├── ConnectConfig.java │ │ │ └── ThreadPoolConfig.java │ │ │ ├── constants │ │ │ ├── ConfigConstant.java │ │ │ ├── ExecutorConstant.java │ │ │ └── TypeConstant.java │ │ │ ├── entity │ │ │ └── CDownloadTaskEntity.java │ │ │ ├── listener │ │ │ └── CDownloadListener.java │ │ │ ├── manager │ │ │ ├── download │ │ │ │ ├── FileManager.java │ │ │ │ └── HTTPSTrustManager.java │ │ │ └── executor │ │ │ │ ├── ExecutorFactory.java │ │ │ │ └── ExecutorManager.java │ │ │ └── util │ │ │ ├── DownloadCheckUtil.java │ │ │ ├── FileUtil.java │ │ │ ├── MD5Util.java │ │ │ └── PathUtil.java │ └── res │ │ └── values │ │ └── strings.xml │ └── test │ └── java │ └── com │ └── zero │ └── cdownload │ └── ExampleUnitTest.java ├── LICENSE ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── example │ │ └── moe233 │ │ └── myapplicationrecycleview │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── zero │ │ │ └── cdownload │ │ │ └── demo │ │ │ ├── MainActivity.java │ │ │ └── MyApplication.java │ └── res │ │ ├── drawable-v24 │ │ └── ic_launcher_foreground.xml │ │ ├── drawable │ │ └── ic_launcher_background.xml │ │ ├── layout │ │ ├── activity_main.xml │ │ └── item.xml │ │ ├── mipmap-anydpi-v26 │ │ ├── ic_launcher.xml │ │ └── ic_launcher_round.xml │ │ ├── mipmap-hdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-mdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xhdpi │ │ ├── ic_launcher.png │ │ ├── ic_launcher_round.png │ │ └── psb.png │ │ ├── mipmap-xxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ └── values │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── example │ └── moe233 │ └── myapplicationrecycleview │ └── ExampleUnitTest.java ├── build.gradle ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | /bin 2 | /gen 3 | /project.properties 4 | /.classpath 5 | 6 | /*.properties 7 | 8 | sh.exe.stackdump 9 | .fbprefs 10 | /bom.xml 11 | /build 12 | .gradle 13 | /*.iml 14 | */*.iml 15 | /.idea 16 | -------------------------------------------------------------------------------- /ClassicDownload/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /ClassicDownload/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | apply plugin: 'com.jfrog.bintray' 3 | // JitPack Maven 4 | apply plugin: 'com.github.dcendents.android-maven' 5 | // Your Group 6 | group='com.github.zerochl' 7 | 8 | version = "0.0.1" 9 | android { 10 | compileSdkVersion 26 11 | 12 | defaultConfig { 13 | minSdkVersion 14 14 | targetSdkVersion 26 15 | versionCode 1 16 | versionName "0.1.1" 17 | 18 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 19 | 20 | } 21 | 22 | buildTypes { 23 | release { 24 | minifyEnabled false 25 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 26 | } 27 | } 28 | lintOptions { 29 | abortOnError false 30 | } 31 | } 32 | 33 | dependencies { 34 | implementation fileTree(dir: 'libs', include: ['*.jar']) 35 | 36 | implementation 'com.android.support:appcompat-v7:26.1.0' 37 | 38 | // rxjava 39 | implementation 'io.reactivex.rxjava2:rxandroid:2.0.2' 40 | implementation 'io.reactivex.rxjava2:rxjava:2.1.12' 41 | } 42 | //publish { 43 | // userOrg = 'novoda' 44 | // groupId = 'com.novoda' 45 | // artifactId = 'bintray-release' 46 | // publishVersion = '0.6.1' 47 | //} 48 | def siteUrl = 'https://github.com/zerochl/ClassisDownload' // 项目的主页 49 | def gitUrl = 'git@github.com:zerochl/ClassisDownload.git' // Git仓库的url 50 | group = "com.zero.cdownload" // Maven Group ID for the artifact,一般填你唯一的包名 51 | install { 52 | repositories.mavenInstaller { 53 | // This generates POM.xml with proper parameters 54 | pom { 55 | project { 56 | packaging 'aar' 57 | // Add your description here 58 | name '找了一天RxDownload的bug,解决不了,懒得去看他的实现,自己写了一套基于RxJava的下载,支持线程池管理、断点续传、下载完成校验、下载中断' //项目的描述 你可以多写一点 59 | url siteUrl 60 | // Set your license 61 | licenses { 62 | license { 63 | name 'The Apache Software License, Version 2.0' 64 | url 'http://www.apache.org/licenses/LICENSE-2.0.txt' 65 | } 66 | } 67 | developers { 68 | developer { 69 | id 'zerochl' //填写的一些基本信息 70 | name 'zerochl' 71 | email 'zerochlwork@gmail.com' 72 | } 73 | } 74 | scm { 75 | connection gitUrl 76 | developerConnection gitUrl 77 | url siteUrl 78 | } 79 | } 80 | } 81 | } 82 | } 83 | task sourcesJar(type: Jar) { 84 | from android.sourceSets.main.java.srcDirs 85 | classifier = 'sources' 86 | } 87 | task javadoc(type: Javadoc) { 88 | source = android.sourceSets.main.java.srcDirs 89 | classpath += project.files(android.getBootClasspath().join(File.pathSeparator)) 90 | } 91 | task javadocJar(type: Jar, dependsOn: javadoc) { 92 | classifier = 'javadoc' 93 | from javadoc.destinationDir 94 | } 95 | artifacts { 96 | archives javadocJar 97 | archives sourcesJar 98 | } 99 | Properties properties = new Properties() 100 | properties.load(project.rootProject.file('local.properties').newDataInputStream()) 101 | bintray { 102 | user = properties.getProperty("bintray.user") 103 | key = properties.getProperty("bintray.apikey") 104 | configurations = ['archives'] 105 | pkg { 106 | repo = "maven" 107 | name = "ClassisDownload" //发布到JCenter上的项目名字 108 | websiteUrl = siteUrl 109 | vcsUrl = gitUrl 110 | licenses = ["Apache-2.0"] 111 | publish = true 112 | } 113 | } -------------------------------------------------------------------------------- /ClassicDownload/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /ClassicDownload/src/androidTest/java/com/zero/cdownload/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.zero.cdownload; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumented test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() throws Exception { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.zero.cdownload.test", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /ClassicDownload/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | -------------------------------------------------------------------------------- /ClassicDownload/src/main/java/com/zero/cdownload/CDownload.java: -------------------------------------------------------------------------------- 1 | package com.zero.cdownload; 2 | 3 | import android.util.Log; 4 | 5 | import com.zero.cdownload.config.CDownloadConfig; 6 | import com.zero.cdownload.constants.ExecutorConstant; 7 | import com.zero.cdownload.constants.TypeConstant; 8 | import com.zero.cdownload.entity.CDownloadTaskEntity; 9 | import com.zero.cdownload.listener.CDownloadListener; 10 | import com.zero.cdownload.manager.download.FileManager; 11 | import com.zero.cdownload.manager.executor.ExecutorManager; 12 | 13 | import java.util.concurrent.ConcurrentHashMap; 14 | 15 | import io.reactivex.Observable; 16 | import io.reactivex.ObservableEmitter; 17 | import io.reactivex.ObservableOnSubscribe; 18 | import io.reactivex.functions.Consumer; 19 | import io.reactivex.schedulers.Schedulers; 20 | 21 | /** 22 | * Created by zero on 2018/4/26. 23 | * 24 | * @author zero 25 | */ 26 | 27 | public class CDownload { 28 | private static CDownload cDownload = new CDownload(); 29 | private CDownloadConfig downloadConfig; 30 | private ConcurrentHashMap downloadTaskList = new ConcurrentHashMap<>(); 31 | 32 | private CDownload() { 33 | } 34 | 35 | public static CDownload getInstance() { 36 | return cDownload; 37 | } 38 | 39 | public CDownload init(CDownloadConfig downloadConfig) { 40 | this.downloadConfig = downloadConfig; 41 | ExecutorManager.init(downloadConfig.getIoThreadPoolConfig()); 42 | FileManager.init(downloadConfig); 43 | return this; 44 | } 45 | 46 | public void create(String url, CDownloadListener downloadListener) { 47 | if (downloadTaskList.containsKey(url)) { 48 | Log.e("HongLi", "had been in task list."); 49 | return; 50 | } 51 | create(url, TypeConstant.THREAD_POOL_TYPE_IO, ExecutorConstant.SINGLE_THREAD_POOL_TYPE_DEFAULE, downloadListener); 52 | } 53 | 54 | public void create(String url, int threadPoolType, CDownloadListener downloadListener) { 55 | if (downloadTaskList.containsKey(url)) { 56 | Log.e("HongLi", "had been in task list."); 57 | return; 58 | } 59 | create(url, threadPoolType, ExecutorConstant.SINGLE_THREAD_POOL_TYPE_DEFAULE, downloadListener); 60 | } 61 | 62 | public void create(String url, int threadPoolType, String singleThreadPoolKey, CDownloadListener downloadListener) { 63 | if (downloadTaskList.containsKey(url)) { 64 | Log.e("HongLi", "had been in task list."); 65 | return; 66 | } 67 | CDownloadTaskEntity newTask = new CDownloadTaskEntity(url, downloadListener, threadPoolType, singleThreadPoolKey); 68 | downloadTaskList.put(url, newTask); 69 | } 70 | 71 | public void create(CDownloadTaskEntity downloadTaskEntity) { 72 | if (downloadTaskEntity == null) { 73 | Log.e("HongLi", "downloadTaskEntity is null."); 74 | return; 75 | } 76 | // create(downloadTaskEntity.getUrl(), downloadTaskEntity.getThreadPoolType(), downloadTaskEntity.getSingleThreadPoolKey(), downloadTaskEntity.getDownloadListener()); 77 | downloadTaskList.put(downloadTaskEntity.getUrl(), downloadTaskEntity); 78 | } 79 | 80 | public void start(String url) { 81 | final CDownloadTaskEntity task = downloadTaskList.get(url); 82 | if (task == null) { 83 | Log.e("HongLi", "in start there is not task in task list"); 84 | return; 85 | } 86 | Observable 87 | .create(new ObservableOnSubscribe() { 88 | @Override 89 | public void subscribe(ObservableEmitter observableEmitter) throws Exception { 90 | observableEmitter.onNext(task); 91 | } 92 | }) 93 | .subscribeOn(ExecutorManager.getRxJavaExecutor(task.getThreadPoolType(), task.getSingleThreadPoolKey())) 94 | .subscribe(new Consumer() { 95 | @Override 96 | public void accept(CDownloadTaskEntity downloadTaskEntity) throws Exception { 97 | FileManager.startDownload(downloadTaskEntity); 98 | removeTask(downloadTaskEntity); 99 | } 100 | }, new Consumer() { 101 | @Override 102 | public void accept(Throwable throwable) throws Exception { 103 | task.getDownloadListener().onError(throwable.getMessage()); 104 | removeTask(task); 105 | } 106 | }); 107 | } 108 | 109 | public void stop(String url){ 110 | CDownloadTaskEntity task = downloadTaskList.get(url); 111 | if (task == null) { 112 | Log.e("HongLi", "in stop there is not task in task list"); 113 | return; 114 | } 115 | removeTask(task); 116 | } 117 | 118 | public CDownloadTaskEntity getTaskByUrl(String url) { 119 | return downloadTaskList.get(url); 120 | } 121 | 122 | private void removeTask(CDownloadTaskEntity task){ 123 | if (task == null) { 124 | Log.e("HongLi", "in removeTask task is null"); 125 | return; 126 | } 127 | task.setHasCancel(true); 128 | downloadTaskList.remove(task.getUrl()); 129 | } 130 | } 131 | -------------------------------------------------------------------------------- /ClassicDownload/src/main/java/com/zero/cdownload/config/CDownloadConfig.java: -------------------------------------------------------------------------------- 1 | package com.zero.cdownload.config; 2 | 3 | import com.zero.cdownload.constants.ConfigConstant; 4 | 5 | /** 6 | * Created by zero on 2018/4/26. 7 | * 8 | * @author zero 9 | */ 10 | 11 | public class CDownloadConfig { 12 | 13 | private String diskCachePath; 14 | //临时文件存放文件夹 15 | private String tempFolderName; 16 | //临时文件后缀 17 | private String tempFileSuffix; 18 | //io线程池config 19 | private ThreadPoolConfig ioThreadPoolConfig; 20 | 21 | private ConnectConfig connectConfig; 22 | // 是否需要检查下载文件的大小 23 | private boolean needCheckFileLength = ConfigConstant.NEED_CHECK_DOWNLOAD_FILE_LENGTH; 24 | 25 | private CDownloadConfig(){ 26 | } 27 | 28 | public static CDownloadConfig build(){ 29 | return new CDownloadConfig(); 30 | } 31 | 32 | public String getDiskCachePath() { 33 | return diskCachePath; 34 | } 35 | 36 | public CDownloadConfig setDiskCachePath(String diskCachePath) { 37 | this.diskCachePath = diskCachePath; 38 | return this; 39 | } 40 | 41 | public String getTempFolderName() { 42 | return tempFolderName; 43 | } 44 | 45 | public CDownloadConfig setTempFolderName(String tempFolderName) { 46 | this.tempFolderName = tempFolderName; 47 | return this; 48 | } 49 | 50 | public String getTempFileSuffix() { 51 | return tempFileSuffix; 52 | } 53 | 54 | public CDownloadConfig setTempFileSuffix(String tempFileSuffix) { 55 | this.tempFileSuffix = tempFileSuffix; 56 | return this; 57 | } 58 | 59 | public ThreadPoolConfig getIoThreadPoolConfig() { 60 | return ioThreadPoolConfig; 61 | } 62 | 63 | public CDownloadConfig setIoThreadPoolConfig(ThreadPoolConfig ioThreadPoolConfig) { 64 | this.ioThreadPoolConfig = ioThreadPoolConfig; 65 | return this; 66 | } 67 | 68 | public ConnectConfig getConnectConfig() { 69 | return connectConfig; 70 | } 71 | 72 | public CDownloadConfig setConnectConfig(ConnectConfig connectConfig) { 73 | this.connectConfig = connectConfig; 74 | return this; 75 | } 76 | 77 | public boolean isNeedCheckFileLength() { 78 | return needCheckFileLength; 79 | } 80 | 81 | public CDownloadConfig setNeedCheckFileLength(boolean needCheckFileLength) { 82 | this.needCheckFileLength = needCheckFileLength; 83 | return this; 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /ClassicDownload/src/main/java/com/zero/cdownload/config/ConnectConfig.java: -------------------------------------------------------------------------------- 1 | package com.zero.cdownload.config; 2 | 3 | /** 4 | * Created by zero on 2018/4/26. 5 | * 6 | * @author zero 7 | */ 8 | 9 | public class ConnectConfig { 10 | private int connectTimeOut; 11 | private int readTimeOut; 12 | private int readBufferSize; 13 | 14 | public static ConnectConfig build(){ 15 | return new ConnectConfig(); 16 | } 17 | 18 | public int getConnectTimeOut() { 19 | return connectTimeOut; 20 | } 21 | 22 | public ConnectConfig setConnectTimeOut(int connectTimeOut) { 23 | this.connectTimeOut = connectTimeOut; 24 | return this; 25 | } 26 | 27 | public int getReadTimeOut() { 28 | return readTimeOut; 29 | } 30 | 31 | public ConnectConfig setReadTimeOut(int readTimeOut) { 32 | this.readTimeOut = readTimeOut; 33 | return this; 34 | } 35 | 36 | public int getReadBufferSize() { 37 | return readBufferSize; 38 | } 39 | 40 | public ConnectConfig setReadBufferSize(int readBufferSize) { 41 | this.readBufferSize = readBufferSize; 42 | return this; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /ClassicDownload/src/main/java/com/zero/cdownload/config/ThreadPoolConfig.java: -------------------------------------------------------------------------------- 1 | package com.zero.cdownload.config; 2 | 3 | import com.zero.cdownload.constants.ExecutorConstant; 4 | 5 | /** 6 | * Created by zero on 2018/4/26. 7 | * 8 | * @author zero 9 | */ 10 | 11 | public class ThreadPoolConfig { 12 | /** 13 | * corePoolSize 池中所保存的线程数,包括空闲线程。 14 | */ 15 | private int corePoolSize = ExecutorConstant.CORE_POOL_SIZE; 16 | 17 | /** 18 | * maximumPoolSize - 池中允许的最大线程数(采用LinkedBlockingQueue时没有作用)。 19 | */ 20 | private int maximumPoolSize = ExecutorConstant.MAXIMUM_POOL_SIZE; 21 | 22 | /** 23 | * keepAliveTime -当线程数大于核心时,此为终止前多余的空闲线程等待新任务的最长时间,线程池维护线程所允许的空闲时间 24 | */ 25 | private int keepAliveTime = ExecutorConstant.KEEP_ALIVE_TIME; 26 | /** 27 | * "线程池"的阻塞队列容量 28 | */ 29 | private int capacity = ExecutorConstant.CAPATITY; 30 | 31 | private ThreadPoolConfig() { 32 | } 33 | 34 | public static ThreadPoolConfig build(){ 35 | return new ThreadPoolConfig(); 36 | } 37 | 38 | public static ThreadPoolConfig getDefaultThreadPoolConfig(){ 39 | return ThreadPoolConfig.build() 40 | .setCorePoolSize(ExecutorConstant.CORE_POOL_SIZE) 41 | .setMaximumPoolSize(ExecutorConstant.MAXIMUM_POOL_SIZE) 42 | .setKeepAliveTime(ExecutorConstant.KEEP_ALIVE_TIME); 43 | } 44 | 45 | public int getCorePoolSize() { 46 | return corePoolSize; 47 | } 48 | 49 | public ThreadPoolConfig setCorePoolSize(int corePoolSize) { 50 | this.corePoolSize = corePoolSize; 51 | return this; 52 | } 53 | 54 | public int getMaximumPoolSize() { 55 | return maximumPoolSize; 56 | } 57 | 58 | public ThreadPoolConfig setMaximumPoolSize(int maximumPoolSize) { 59 | this.maximumPoolSize = maximumPoolSize; 60 | return this; 61 | } 62 | 63 | public int getKeepAliveTime() { 64 | return keepAliveTime; 65 | } 66 | 67 | public ThreadPoolConfig setKeepAliveTime(int keepAliveTime) { 68 | this.keepAliveTime = keepAliveTime; 69 | return this; 70 | } 71 | 72 | public int getCapacity() { 73 | return capacity; 74 | } 75 | 76 | public ThreadPoolConfig setCapacity(int capacity) { 77 | this.capacity = capacity; 78 | return this; 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /ClassicDownload/src/main/java/com/zero/cdownload/constants/ConfigConstant.java: -------------------------------------------------------------------------------- 1 | package com.zero.cdownload.constants; 2 | 3 | /** 4 | * Created by zero on 2018/4/26. 5 | * 6 | * @author zero 7 | */ 8 | 9 | public class ConfigConstant { 10 | public static final String DEFAULT_DOWNLOAD_PATH = "cdownload"; 11 | 12 | public static final String DEFAULT_TEMP_FOLDER_NAME = "TEMP"; 13 | 14 | public static final int TIME_DEFAULT_CONNECT_OUT = 10000; 15 | public static final int TIME_DEFAULT_READ_OUT = 20000; 16 | 17 | public static final int BUFFER_DEFAULT_DOWNLOAD = 2048; 18 | 19 | public static final boolean NEED_CHECK_DOWNLOAD_FILE_LENGTH = true; 20 | } 21 | -------------------------------------------------------------------------------- /ClassicDownload/src/main/java/com/zero/cdownload/constants/ExecutorConstant.java: -------------------------------------------------------------------------------- 1 | package com.zero.cdownload.constants; 2 | 3 | /** 4 | * Created by zero on 2018/4/26. 5 | * 6 | * @author zero 7 | */ 8 | 9 | public class ExecutorConstant { 10 | /** 11 | * corePoolSize 池中所保存的线程数,包括空闲线程。 12 | */ 13 | public static final int CORE_POOL_SIZE = 4; 14 | /** 15 | * maximumPoolSize - 池中允许的最大线程数(采用LinkedBlockingQueue时没有作用)。 16 | */ 17 | public static final int MAXIMUM_POOL_SIZE = 100; 18 | /** 19 | * keepAliveTime -当线程数大于核心时,此为终止前多余的空闲线程等待新任务的最长时间,线程池维护线程所允许的空闲时间 20 | * MILLISECONDS 21 | */ 22 | public static final int KEEP_ALIVE_TIME = 60; 23 | /** 24 | * "线程池"的阻塞队列容量 25 | */ 26 | public static final int CAPATITY = 50; 27 | 28 | public static final String SINGLE_THREAD_POOL_TYPE_DEFAULE = "DEFAULT_CLASSIC_DOWNLOAD_SINGLE_THREAD_POOL_TYPE"; 29 | } 30 | -------------------------------------------------------------------------------- /ClassicDownload/src/main/java/com/zero/cdownload/constants/TypeConstant.java: -------------------------------------------------------------------------------- 1 | package com.zero.cdownload.constants; 2 | 3 | /** 4 | * Created by zero on 2018/4/26. 5 | * 6 | * @author zero 7 | */ 8 | 9 | public class TypeConstant { 10 | public static final int THREAD_POOL_TYPE_SINGLE = 0; 11 | public static final int THREAD_POOL_TYPE_IO = 1; 12 | public static final int THREAD_POOL_TYPE_SINGLE_DISCARD = 2; 13 | } 14 | -------------------------------------------------------------------------------- /ClassicDownload/src/main/java/com/zero/cdownload/entity/CDownloadTaskEntity.java: -------------------------------------------------------------------------------- 1 | package com.zero.cdownload.entity; 2 | 3 | import com.zero.cdownload.listener.CDownloadListener; 4 | 5 | /** 6 | * Created by zero on 2018/4/26. 7 | * 8 | * @author zero 9 | */ 10 | 11 | public class CDownloadTaskEntity { 12 | private String url; 13 | private CDownloadListener downloadListener; 14 | private boolean hasCancel = false; 15 | private int threadPoolType; 16 | private String singleThreadPoolKey; 17 | private boolean needMD5Name = false; 18 | 19 | public CDownloadTaskEntity() { 20 | } 21 | 22 | public CDownloadTaskEntity(String url, CDownloadListener downloadListener) { 23 | this.url = url; 24 | this.downloadListener = downloadListener; 25 | } 26 | 27 | public CDownloadTaskEntity(String url, CDownloadListener downloadListener, int threadPoolType) { 28 | this.url = url; 29 | this.downloadListener = downloadListener; 30 | this.threadPoolType = threadPoolType; 31 | } 32 | 33 | public CDownloadTaskEntity(String url, CDownloadListener downloadListener, int threadPoolType, String singleThreadPoolKey) { 34 | this.url = url; 35 | this.downloadListener = downloadListener; 36 | this.threadPoolType = threadPoolType; 37 | this.singleThreadPoolKey = singleThreadPoolKey; 38 | } 39 | 40 | public static CDownloadTaskEntity build(){ 41 | return new CDownloadTaskEntity(); 42 | } 43 | 44 | public String getUrl() { 45 | return url; 46 | } 47 | 48 | public CDownloadTaskEntity setUrl(String url) { 49 | this.url = url; 50 | return this; 51 | } 52 | 53 | public CDownloadListener getDownloadListener() { 54 | return downloadListener; 55 | } 56 | 57 | public CDownloadTaskEntity setDownloadListener(CDownloadListener downloadListener) { 58 | this.downloadListener = downloadListener; 59 | return this; 60 | } 61 | 62 | public boolean isHasCancel() { 63 | return hasCancel; 64 | } 65 | 66 | public CDownloadTaskEntity setHasCancel(boolean hasCancel) { 67 | this.hasCancel = hasCancel; 68 | return this; 69 | } 70 | 71 | public int getThreadPoolType() { 72 | return threadPoolType; 73 | } 74 | 75 | public CDownloadTaskEntity setThreadPoolType(int threadPoolType) { 76 | this.threadPoolType = threadPoolType; 77 | return this; 78 | } 79 | 80 | public String getSingleThreadPoolKey() { 81 | return singleThreadPoolKey; 82 | } 83 | 84 | public CDownloadTaskEntity setSingleThreadPoolKey(String singleThreadPoolKey) { 85 | this.singleThreadPoolKey = singleThreadPoolKey; 86 | return this; 87 | } 88 | 89 | public boolean isNeedMD5Name() { 90 | return needMD5Name; 91 | } 92 | 93 | public CDownloadTaskEntity setNeedMD5Name(boolean needMD5Name) { 94 | this.needMD5Name = needMD5Name; 95 | return this; 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /ClassicDownload/src/main/java/com/zero/cdownload/listener/CDownloadListener.java: -------------------------------------------------------------------------------- 1 | package com.zero.cdownload.listener; 2 | 3 | /** 4 | * Created by zero on 2018/4/26. 5 | * 6 | * @author zero 7 | */ 8 | 9 | public interface CDownloadListener { 10 | void onPreStart(); 11 | void onProgress(long maxSIze, long currentSize); 12 | void onComplete(String localFilePath); 13 | void onError(String errorMessage); 14 | void onCancel(); 15 | } 16 | -------------------------------------------------------------------------------- /ClassicDownload/src/main/java/com/zero/cdownload/manager/download/FileManager.java: -------------------------------------------------------------------------------- 1 | package com.zero.cdownload.manager.download; 2 | 3 | import android.os.Environment; 4 | import android.text.TextUtils; 5 | import android.util.Log; 6 | 7 | import com.zero.cdownload.config.CDownloadConfig; 8 | import com.zero.cdownload.constants.ConfigConstant; 9 | import com.zero.cdownload.entity.CDownloadTaskEntity; 10 | import com.zero.cdownload.util.DownloadCheckUtil; 11 | import com.zero.cdownload.util.FileUtil; 12 | import com.zero.cdownload.util.PathUtil; 13 | 14 | import java.io.File; 15 | import java.io.IOException; 16 | import java.io.InputStream; 17 | import java.io.RandomAccessFile; 18 | import java.net.HttpURLConnection; 19 | import java.net.MalformedURLException; 20 | import java.net.URL; 21 | 22 | /** 23 | * Created by zero on 2018/4/26. 24 | * 25 | * @author zero 26 | */ 27 | 28 | public class FileManager { 29 | 30 | private static final String TAG = FileManager.class.getCanonicalName(); 31 | 32 | private static int connectTimeOut = ConfigConstant.TIME_DEFAULT_CONNECT_OUT; 33 | private static int readTimeOut = ConfigConstant.TIME_DEFAULT_READ_OUT; 34 | private static boolean needCheckFileLength = ConfigConstant.NEED_CHECK_DOWNLOAD_FILE_LENGTH; 35 | 36 | private static int bufferSize = ConfigConstant.BUFFER_DEFAULT_DOWNLOAD; 37 | private static String cachePath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/com/zero/cdownload"; 38 | 39 | public static void init(CDownloadConfig downloadConfig) { 40 | HTTPSTrustManager.allowAllSSL(); 41 | if (null == downloadConfig) { 42 | return; 43 | } 44 | needCheckFileLength = downloadConfig.isNeedCheckFileLength(); 45 | if (downloadConfig.getConnectConfig() != null) { 46 | connectTimeOut = downloadConfig.getConnectConfig().getConnectTimeOut() != 0 ? downloadConfig.getConnectConfig().getConnectTimeOut() : ConfigConstant.TIME_DEFAULT_CONNECT_OUT; 47 | readTimeOut = downloadConfig.getConnectConfig().getReadTimeOut() != 0 ? downloadConfig.getConnectConfig().getReadTimeOut() : ConfigConstant.TIME_DEFAULT_READ_OUT; 48 | bufferSize = downloadConfig.getConnectConfig().getReadBufferSize() != 0 ? downloadConfig.getConnectConfig().getReadBufferSize() : ConfigConstant.BUFFER_DEFAULT_DOWNLOAD; 49 | } 50 | if (!TextUtils.isEmpty(downloadConfig.getDiskCachePath())) { 51 | cachePath = downloadConfig.getDiskCachePath(); 52 | } 53 | } 54 | 55 | public static void startDownload(CDownloadTaskEntity taskEntity) { 56 | if (taskEntity == null || taskEntity.getDownloadListener() == null) { 57 | Log.e(TAG, "in startDownload task entity is null or download listener is null."); 58 | return; 59 | } 60 | taskEntity.getDownloadListener().onPreStart(); 61 | String localFilePath = PathUtil.getLocalFilePath(taskEntity.getUrl(), cachePath, taskEntity.isNeedMD5Name()); 62 | String templocalFilePath = PathUtil.getLocalFilePath(taskEntity.getUrl(), cachePath + "/" + ConfigConstant.DEFAULT_TEMP_FOLDER_NAME, taskEntity.isNeedMD5Name()); 63 | Log.d(TAG, "templocalFilePath:" + templocalFilePath); 64 | if (FileUtil.isExist(localFilePath) && DownloadCheckUtil.checkFileDownloadOk(taskEntity.getUrl(), localFilePath, needCheckFileLength)) { 65 | //文件已经下载成功,不需要执行下载操作 66 | taskEntity.getDownloadListener().onComplete(localFilePath); 67 | } else { 68 | //先删除本地文件,如果有 69 | FileUtil.deleteFile(localFilePath); 70 | boolean downloadResult = downloadFile(taskEntity.getUrl(), templocalFilePath, taskEntity); 71 | if (downloadResult) { 72 | if (DownloadCheckUtil.checkFileDownloadOk(taskEntity.getUrl(), templocalFilePath, needCheckFileLength)) { 73 | //执行文件替换操作 74 | synchronized (FileManager.class) { 75 | //文件不存在才执行替换操作 76 | FileUtil.rename(templocalFilePath, localFilePath); 77 | FileUtil.deleteFile(templocalFilePath); 78 | taskEntity.getDownloadListener().onComplete(localFilePath); 79 | } 80 | } else { 81 | //下载成功,但是校验失败 82 | FileUtil.deleteFile(templocalFilePath); 83 | taskEntity.getDownloadListener().onError("download success but check error."); 84 | } 85 | } else if (!taskEntity.isHasCancel()) { 86 | taskEntity.getDownloadListener().onError("download error."); 87 | } 88 | } 89 | } 90 | 91 | /** 92 | * 断点续传下载文件 93 | * 94 | * @param fileUrl 95 | * @param localFilePath 96 | * @return 97 | */ 98 | public static boolean downloadFile(String fileUrl, String localFilePath, CDownloadTaskEntity taskEntity) { 99 | if (TextUtils.isEmpty(fileUrl) || TextUtils.isEmpty(localFilePath) || taskEntity == null || taskEntity.getDownloadListener() == null) { 100 | return false; 101 | } 102 | Log.d(TAG, "start download file:" + fileUrl); 103 | File file = new File(localFilePath); 104 | long size = 0; 105 | if (file.exists()) { 106 | size = file.length(); 107 | } 108 | URL url; 109 | boolean downloadSuccess = false; 110 | long maxSize = 0; 111 | RandomAccessFile out = null; 112 | HttpURLConnection con = null; 113 | try { 114 | url = new URL(fileUrl); 115 | con = (HttpURLConnection) url.openConnection(); 116 | con.setRequestMethod("GET"); 117 | con.setConnectTimeout(connectTimeOut); 118 | con.setReadTimeout(readTimeOut); 119 | // 设置下载区间 120 | con.setRequestProperty("range", "bytes=" + size + "-"); 121 | con.connect(); 122 | maxSize = con.getContentLength(); 123 | long currentSize = 0; 124 | // 只要断点下载,返回的已经不是200,206 125 | int code = con.getResponseCode(); 126 | if (code == 301 || code == 302) { 127 | return downloadFile(con.getHeaderField("Location"), localFilePath, taskEntity); 128 | } 129 | if (code == 206) { 130 | InputStream in = con.getInputStream(); 131 | // int serverSize = con.getContentLength(); 132 | // 必须要使用 133 | out = new RandomAccessFile(file, "rw"); 134 | out.seek(size); 135 | currentSize = size; 136 | byte[] b = new byte[bufferSize]; 137 | int len = -1; 138 | boolean hasCancel = false; 139 | while ((len = in.read(b)) != -1) { 140 | if (taskEntity.isHasCancel()) { 141 | Log.e(TAG, "cancel download:" + fileUrl); 142 | taskEntity.getDownloadListener().onCancel(); 143 | hasCancel = true; 144 | break; 145 | } 146 | out.write(b, 0, len); 147 | currentSize += len; 148 | taskEntity.getDownloadListener().onProgress(maxSize, currentSize); 149 | } 150 | out.close(); 151 | downloadSuccess = !hasCancel; 152 | } else { 153 | //不支持断点续传,先删除缓存文件 154 | FileUtil.deleteFile(localFilePath); 155 | downloadSuccess = downloadFileNormal(fileUrl, localFilePath, taskEntity); 156 | } 157 | con.disconnect(); 158 | } catch (MalformedURLException e) { 159 | e.printStackTrace(); 160 | downloadSuccess = downloadFileNormal(fileUrl, localFilePath, taskEntity); 161 | Log.e(TAG, "error url:" + fileUrl); 162 | } catch (IOException e) { 163 | e.printStackTrace(); 164 | downloadSuccess = downloadFileNormal(fileUrl, localFilePath, taskEntity); 165 | } catch (Exception e) { 166 | e.printStackTrace(); 167 | downloadSuccess = downloadFileNormal(fileUrl, localFilePath, taskEntity); 168 | } finally { 169 | try { 170 | if (null != out) { 171 | out.close(); 172 | } 173 | } catch (IOException e1) { 174 | e1.printStackTrace(); 175 | } 176 | if (null != con) { 177 | con.disconnect(); 178 | } 179 | //通过文件长度来判断下载是否成功 180 | if (!downloadSuccess || !file.exists()) { 181 | downloadSuccess = false; 182 | } 183 | } 184 | Log.d(TAG, "end download file:" + fileUrl); 185 | return downloadSuccess; 186 | } 187 | 188 | /** 189 | * 不支持断点续传下载文件:使用服务端缓存,不能使用断点续传功能,除非它支持 190 | * 191 | * @param fileUrl 192 | * @param localFilePath 193 | * @add by ytxu 2015-10-27 194 | */ 195 | private static boolean downloadFileNormal(String fileUrl, 196 | String localFilePath, CDownloadTaskEntity taskEntity) { 197 | if (TextUtils.isEmpty(fileUrl) || TextUtils.isEmpty(localFilePath) || taskEntity == null || taskEntity.getDownloadListener() == null) { 198 | return false; 199 | } 200 | File file = new File(localFilePath); 201 | long size = 0; 202 | if (file.exists()) { 203 | size = file.length(); 204 | } 205 | URL url; 206 | boolean downloadSuccess = false; 207 | RandomAccessFile out = null; 208 | HttpURLConnection con = null; 209 | long maxSize = 0; 210 | try { 211 | url = new URL(fileUrl); 212 | con = (HttpURLConnection) url.openConnection(); 213 | con.setRequestMethod("GET"); 214 | con.setConnectTimeout(connectTimeOut); 215 | con.setReadTimeout(readTimeOut); 216 | // //设置下载区间 217 | // con.setRequestProperty("range","bytes="+size+"-"); 218 | // if(null != fileAttr && 0 != fileAttr.length && null != fileAttr[0]){ 219 | // con.setIfModifiedSince(Long.parseLong(fileAttr[0].getEtag())); 220 | // } 221 | con.connect(); 222 | maxSize = con.getContentLength(); 223 | long currentSize = 0; 224 | int code = con.getResponseCode();// 只要断点下载,返回的已经不是200,206 225 | if (code == 301 || code == 302) { 226 | return downloadFile(con.getHeaderField("Location"), localFilePath, taskEntity); 227 | } 228 | // if(code==206){ 229 | if (code == 200) { 230 | InputStream in = con.getInputStream(); 231 | // int serverSize = con.getContentLength(); 232 | // 必须要使用 233 | out = new RandomAccessFile(file, "rw"); 234 | out.seek(size); 235 | currentSize = size; 236 | byte[] b = new byte[bufferSize]; 237 | int len = -1; 238 | boolean hasCancel = false; 239 | while ((len = in.read(b)) != -1) { 240 | if (taskEntity.isHasCancel()) { 241 | Log.e(TAG, "cancel download:" + fileUrl); 242 | taskEntity.getDownloadListener().onCancel(); 243 | hasCancel = true; 244 | break; 245 | } 246 | out.write(b, 0, len); 247 | currentSize += len; 248 | taskEntity.getDownloadListener().onProgress(maxSize, currentSize); 249 | } 250 | // if(null != fileAttr && 0 != fileAttr.length && null != fileAttr[0]){ 251 | // fileAttr[0].setEtag(con.getLastModified() + ""); 252 | // } 253 | out.close(); 254 | downloadSuccess = !hasCancel; 255 | } else { 256 | downloadSuccess = false; 257 | } 258 | 259 | con.disconnect(); 260 | } catch (MalformedURLException e) { 261 | e.printStackTrace(); 262 | } catch (IOException e) { 263 | e.printStackTrace(); 264 | } catch (Exception e) { 265 | e.printStackTrace(); 266 | } finally { 267 | try { 268 | if (null != out) { 269 | out.close(); 270 | } 271 | } catch (IOException e1) { 272 | e1.printStackTrace(); 273 | } 274 | if (null != con) { 275 | con.disconnect(); 276 | } 277 | if (!downloadSuccess || !file.exists()) { 278 | downloadSuccess = false; 279 | } 280 | } 281 | return downloadSuccess; 282 | } 283 | } 284 | -------------------------------------------------------------------------------- /ClassicDownload/src/main/java/com/zero/cdownload/manager/download/HTTPSTrustManager.java: -------------------------------------------------------------------------------- 1 | package com.zero.cdownload.manager.download; 2 | 3 | import java.security.KeyManagementException; 4 | import java.security.NoSuchAlgorithmException; 5 | import java.security.SecureRandom; 6 | import java.security.cert.X509Certificate; 7 | 8 | import javax.net.ssl.HostnameVerifier; 9 | import javax.net.ssl.HttpsURLConnection; 10 | import javax.net.ssl.SSLContext; 11 | import javax.net.ssl.SSLSession; 12 | import javax.net.ssl.TrustManager; 13 | import javax.net.ssl.X509TrustManager; 14 | 15 | /** 16 | * Created by zero on 2018/4/26. 17 | * 18 | * @author zero 19 | */ 20 | 21 | public class HTTPSTrustManager implements X509TrustManager { 22 | 23 | private static TrustManager[] trustManagers; 24 | private static final X509Certificate[] _AcceptedIssuers = new X509Certificate[] {}; 25 | 26 | @Override 27 | public void checkClientTrusted( 28 | java.security.cert.X509Certificate[] x509Certificates, String s) 29 | throws java.security.cert.CertificateException { 30 | // To change body of implemented methods use File | Settings | File 31 | // Templates. 32 | } 33 | 34 | @Override 35 | public void checkServerTrusted( 36 | java.security.cert.X509Certificate[] x509Certificates, String s) 37 | throws java.security.cert.CertificateException { 38 | // To change body of implemented methods use File | Settings | File 39 | // Templates. 40 | } 41 | 42 | @Override 43 | public X509Certificate[] getAcceptedIssuers() { 44 | return _AcceptedIssuers; 45 | } 46 | 47 | public static void allowAllSSL() { 48 | HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() { 49 | 50 | @Override 51 | public boolean verify(String arg0, SSLSession arg1) { 52 | // TODO Auto-generated method stub 53 | return true; 54 | } 55 | 56 | }); 57 | 58 | SSLContext context = null; 59 | if (trustManagers == null) { 60 | trustManagers = new TrustManager[] { new HTTPSTrustManager() }; 61 | } 62 | 63 | try { 64 | context = SSLContext.getInstance("TLS"); 65 | context.init(null, trustManagers, new SecureRandom()); 66 | } catch (NoSuchAlgorithmException e) { 67 | e.printStackTrace(); 68 | } catch (KeyManagementException e) { 69 | e.printStackTrace(); 70 | } 71 | HttpsURLConnection.setDefaultSSLSocketFactory(context.getSocketFactory()); 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /ClassicDownload/src/main/java/com/zero/cdownload/manager/executor/ExecutorFactory.java: -------------------------------------------------------------------------------- 1 | package com.zero.cdownload.manager.executor; 2 | 3 | import com.zero.cdownload.config.ThreadPoolConfig; 4 | 5 | import java.util.concurrent.ArrayBlockingQueue; 6 | import java.util.concurrent.Executor; 7 | import java.util.concurrent.ExecutorService; 8 | import java.util.concurrent.Executors; 9 | import java.util.concurrent.LinkedBlockingQueue; 10 | import java.util.concurrent.ThreadPoolExecutor; 11 | import java.util.concurrent.TimeUnit; 12 | 13 | /** 14 | * Created by zero on 2018/4/26. 15 | * 16 | * @author zero 17 | */ 18 | 19 | public class ExecutorFactory { 20 | // 构造方法私有化 21 | private ExecutorFactory() { 22 | } 23 | 24 | /** 25 | * 按需创建线程池 26 | * @param threadPoolConfig 27 | * @return 28 | */ 29 | public static Executor newFixedThreadPool(ThreadPoolConfig threadPoolConfig) { 30 | return new ThreadPoolExecutor(threadPoolConfig.getCorePoolSize(), threadPoolConfig.getMaximumPoolSize(), threadPoolConfig.getKeepAliveTime(), TimeUnit.MILLISECONDS, 31 | new LinkedBlockingQueue(), new ThreadPoolExecutor.CallerRunsPolicy()); 32 | } 33 | 34 | /** 35 | * 创建可丢弃之前任务的线程池 36 | * 丢弃队列最前面的任务,然后重新尝试执行任务(重复此过程) 37 | * @param threadPoolConfig 38 | * @return 39 | */ 40 | public static Executor newDiscardOldThreadPool(ThreadPoolConfig threadPoolConfig) { 41 | return new ThreadPoolExecutor(threadPoolConfig.getCorePoolSize(), threadPoolConfig.getMaximumPoolSize(), threadPoolConfig.getKeepAliveTime(), TimeUnit.MILLISECONDS, 42 | new ArrayBlockingQueue(threadPoolConfig.getCapacity()), new ThreadPoolExecutor.DiscardOldestPolicy()); 43 | } 44 | 45 | /** 46 | * 创建单线程池 47 | * @return 48 | */ 49 | public static Executor newSingleThreadExecutor() { 50 | return Executors.newSingleThreadExecutor(); 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /ClassicDownload/src/main/java/com/zero/cdownload/manager/executor/ExecutorManager.java: -------------------------------------------------------------------------------- 1 | package com.zero.cdownload.manager.executor; 2 | 3 | import com.zero.cdownload.config.ThreadPoolConfig; 4 | import com.zero.cdownload.constants.TypeConstant; 5 | 6 | import java.util.HashMap; 7 | import java.util.concurrent.Executor; 8 | 9 | import io.reactivex.Scheduler; 10 | import io.reactivex.schedulers.Schedulers; 11 | 12 | /** 13 | * Created by zero on 2018/4/26. 14 | * 15 | * @author zero 16 | */ 17 | 18 | public class ExecutorManager { 19 | private static HashMap singleExecutorMap = new HashMap<>(); 20 | private static Executor normalExecutor; 21 | 22 | /** 23 | * 初始化线程池 24 | * @param threadPoolConfig 如果传入参数为null,会创建default线程池 25 | */ 26 | public static synchronized void init(ThreadPoolConfig threadPoolConfig){ 27 | if (threadPoolConfig == null) { 28 | threadPoolConfig = ThreadPoolConfig.getDefaultThreadPoolConfig(); 29 | } 30 | normalExecutor = ExecutorFactory.newFixedThreadPool(threadPoolConfig); 31 | //因为是静态变量,防止应用非正常退出之后异常 32 | clear(); 33 | } 34 | 35 | public static synchronized Scheduler getRxJavaExecutor(int type, String singleThreadPoolKey){ 36 | return Schedulers.from(getExecutor(type, singleThreadPoolKey)); 37 | } 38 | 39 | public static synchronized Executor getExecutor(int type, String singleThreadPoolKey){ 40 | Executor executor; 41 | switch (type) { 42 | case TypeConstant.THREAD_POOL_TYPE_IO: 43 | executor = getNormalExecutor(); 44 | break; 45 | case TypeConstant.THREAD_POOL_TYPE_SINGLE: 46 | executor = getSingleExecutorByKey(singleThreadPoolKey); 47 | break; 48 | case TypeConstant.THREAD_POOL_TYPE_SINGLE_DISCARD: 49 | executor = getSingleDiscardExecutor(singleThreadPoolKey); 50 | break; 51 | default: 52 | executor = getNormalExecutor(); 53 | break; 54 | } 55 | return executor; 56 | } 57 | 58 | /** 59 | * key作为单线程吃的唯一值,不同的key可以产生不同的单线程池 60 | * @param key 61 | * @return 62 | */ 63 | public static synchronized Executor getSingleExecutorByKey(String key){ 64 | Executor singleExecutor = singleExecutorMap.get(key); 65 | if(null == singleExecutor){ 66 | singleExecutor = ExecutorFactory.newSingleThreadExecutor(); 67 | singleExecutorMap.put(key,singleExecutor); 68 | } 69 | return singleExecutor; 70 | } 71 | 72 | /** 73 | * 线程池配置,未使用key进行区分,因为意义不大 74 | * @return 75 | */ 76 | public static synchronized Executor getNormalExecutor(){ 77 | if (normalExecutor == null) { 78 | init(null); 79 | } 80 | return normalExecutor; 81 | } 82 | 83 | public static synchronized Executor getSingleDiscardExecutor(String key) { 84 | Executor singleExecutor = singleExecutorMap.get(key); 85 | if (null == singleExecutor) { 86 | singleExecutor = ExecutorFactory.newDiscardOldThreadPool(ThreadPoolConfig.build().setCorePoolSize(1).setCapacity(1).setMaximumPoolSize(1)); 87 | singleExecutorMap.put(key, singleExecutor); 88 | } 89 | return singleExecutor; 90 | } 91 | 92 | public static void clear(){ 93 | singleExecutorMap.clear(); 94 | } 95 | 96 | } 97 | -------------------------------------------------------------------------------- /ClassicDownload/src/main/java/com/zero/cdownload/util/DownloadCheckUtil.java: -------------------------------------------------------------------------------- 1 | package com.zero.cdownload.util; 2 | 3 | import android.text.TextUtils; 4 | 5 | /** 6 | * Created by zero on 2018/4/26. 7 | * 8 | * @author zero 9 | */ 10 | 11 | public class DownloadCheckUtil { 12 | /** 13 | * 校验文件下载是否成功 14 | * @param netUrl 15 | * @param localFileUrl 16 | * @param needCheckLength 17 | * @return 18 | */ 19 | public static boolean checkFileDownloadOk(String netUrl,String localFileUrl, boolean needCheckLength){ 20 | if (TextUtils.isEmpty(netUrl) || TextUtils.isEmpty(localFileUrl) || !FileUtil.isExist(localFileUrl)) { 21 | return false; 22 | } 23 | if (!needCheckLength) { 24 | return true; 25 | } 26 | if (FileUtil.getNetFileLength(netUrl) == FileUtil.getLocalFileLength(localFileUrl)) { 27 | return true; 28 | } 29 | return false; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /ClassicDownload/src/main/java/com/zero/cdownload/util/FileUtil.java: -------------------------------------------------------------------------------- 1 | package com.zero.cdownload.util; 2 | 3 | import android.text.TextUtils; 4 | 5 | import java.io.File; 6 | import java.io.FileInputStream; 7 | import java.io.FileNotFoundException; 8 | import java.io.FileOutputStream; 9 | import java.io.IOException; 10 | import java.io.InputStream; 11 | import java.net.HttpURLConnection; 12 | import java.net.MalformedURLException; 13 | import java.net.URL; 14 | import java.util.Date; 15 | 16 | /** 17 | * Created by zero on 2018/4/26. 18 | * 19 | * @author zero 20 | */ 21 | 22 | public class FileUtil { 23 | public static String getName(String path) { 24 | return new File(path).getName(); 25 | } 26 | 27 | /** 28 | * 如果文件夹不存在会自动创建 29 | * 30 | * @param folderPath 31 | * @return 32 | */ 33 | public static File getFolderByPath(String folderPath) { 34 | if (TextUtils.isEmpty(folderPath)) { 35 | return null; 36 | } 37 | File folder = new File(folderPath); 38 | if (!folder.exists()) { 39 | folder.mkdirs(); 40 | } 41 | return folder; 42 | } 43 | 44 | public static boolean isExist(String filePath) { 45 | if (TextUtils.isEmpty(filePath)) { 46 | return false; 47 | } 48 | File file = new File(filePath); 49 | return file.exists(); 50 | } 51 | 52 | public static boolean deleteFile(String filePath) { 53 | if (TextUtils.isEmpty(filePath)) { 54 | return false; 55 | } 56 | File file = new File(filePath); 57 | return deleteFile(file); 58 | } 59 | 60 | public static boolean deleteFile(File file) { 61 | if (null == file) { 62 | return false; 63 | } 64 | if (file.exists()) { 65 | return file.delete(); 66 | } 67 | return true; 68 | } 69 | 70 | /** 71 | * 删除目录(文件夹)以及目录下的文件 72 | * 73 | * @param sPath 被删除目录的文件路径 74 | * @return 目录删除成功返回true,否则返回false 75 | */ 76 | public static boolean deleteDirectory(String sPath) { 77 | //如果sPath不以文件分隔符结尾,自动添加文件分隔符 78 | if (!sPath.endsWith(File.separator)) { 79 | sPath = sPath + File.separator; 80 | } 81 | File dirFile = new File(sPath); 82 | //如果dir对应的文件不存在,或者不是一个目录,则退出 83 | if (!dirFile.exists() || !dirFile.isDirectory()) { 84 | return false; 85 | } 86 | boolean flag = true; 87 | //删除文件夹下的所有文件(包括子目录) 88 | File[] files = dirFile.listFiles(); 89 | for (int i = 0; i < files.length; i++) { 90 | //删除子文件 91 | if (files[i].isFile()) { 92 | flag = deleteFile(files[i].getAbsolutePath()); 93 | if (!flag) break; 94 | } //删除子目录 95 | else { 96 | flag = deleteDirectory(files[i].getAbsolutePath()); 97 | if (!flag) break; 98 | } 99 | } 100 | if (!flag) return false; 101 | //删除当前目录 102 | if (dirFile.delete()) { 103 | return true; 104 | } else { 105 | return false; 106 | } 107 | } 108 | 109 | /** 110 | * 获取本地文件的length 111 | * @param localFilePath 112 | * @return 113 | */ 114 | public static long getLocalFileLength(String localFilePath) { 115 | if (TextUtils.isEmpty(localFilePath) || !isExist(localFilePath)) { 116 | return 0; 117 | } 118 | return new File(localFilePath).length(); 119 | } 120 | 121 | /** 122 | * 去服务端请求文件大小 123 | * 124 | * @param url 125 | * @return 126 | */ 127 | public static int getNetFileLength(String url) { 128 | if (TextUtils.isEmpty(url)) { 129 | return 0; 130 | } 131 | try { 132 | return getNetFileLength(new URL(url)); 133 | } catch (MalformedURLException e) { 134 | e.printStackTrace(); 135 | } 136 | return 0; 137 | } 138 | 139 | /** 140 | * 去服务端请求文件大小 141 | * 142 | * @param url 143 | * @return 144 | */ 145 | public static int getNetFileLength(URL url) { 146 | if (null == url) { 147 | return 0; 148 | } 149 | int size = 0; 150 | HttpURLConnection con = null; 151 | try { 152 | con = (HttpURLConnection) url.openConnection(); 153 | con.setRequestMethod("GET"); 154 | con.connect(); 155 | size = con.getContentLength(); 156 | con.disconnect(); 157 | } catch (IOException e) { 158 | e.printStackTrace(); 159 | if (null != con) { 160 | con.disconnect(); 161 | } 162 | } 163 | return size; 164 | } 165 | 166 | /** 167 | * 给文件重新命名 168 | * @param fromFilePath 原始文件名 169 | * @param toFilePath rename之后的文件名 170 | * @author ChenHongLi 171 | */ 172 | public static void rename(String fromFilePath,String toFilePath){ 173 | if(TextUtils.isEmpty(fromFilePath) || TextUtils.isEmpty(toFilePath)){ 174 | return; 175 | } 176 | File fromFile = new File(fromFilePath); 177 | File toFile = new File(toFilePath); 178 | if(fromFile.exists()){ 179 | if(toFile.exists()){ 180 | toFile.delete(); 181 | toFile = new File(toFilePath); 182 | } 183 | fromFile.renameTo(toFile); 184 | } 185 | } 186 | /** 187 | * 文件移动 188 | * @param localFilePath 189 | * @param folderPath 190 | * @return 191 | */ 192 | public static boolean moveTo(String localFilePath,String folderPath){ 193 | if(TextUtils.isEmpty(localFilePath) || TextUtils.isEmpty(folderPath) || !isExist(localFilePath)){ 194 | return false; 195 | } 196 | File folderPathFile = new File(folderPath); 197 | return moveAs(localFilePath, folderPathFile.getAbsolutePath() + File.separator + new Date().toString() + ".png", folderPath); 198 | } 199 | /** 200 | * 文件移动 201 | * @param localFilePath 202 | * @param distanceFilePath 203 | * @param folderPath 204 | * @return 205 | */ 206 | public static boolean moveAs(String localFilePath,String distanceFilePath,String folderPath){ 207 | if(TextUtils.isEmpty(localFilePath) || TextUtils.isEmpty(distanceFilePath) || !isExist(localFilePath) || TextUtils.isEmpty(folderPath)){ 208 | return false; 209 | } 210 | File localFile = new File(localFilePath); 211 | File folderPathFile = new File(folderPath); 212 | File distanceFile = new File(distanceFilePath); 213 | if (!folderPathFile.exists()) 214 | folderPathFile.mkdirs(); 215 | return localFile.renameTo(distanceFile); 216 | } 217 | /** 218 | * 文件复制 219 | * @param localFilePath 220 | * @param folderPath 221 | * @return 222 | */ 223 | public static boolean copyTo(String localFilePath,String folderPath){ 224 | if(TextUtils.isEmpty(localFilePath) || TextUtils.isEmpty(folderPath) || !isExist(localFilePath)){ 225 | return false; 226 | } 227 | File folderPathFile = new File(folderPath); 228 | return copyAs(localFilePath, folderPathFile.getAbsolutePath() + File.separator + new Date().toString() + ".png", folderPath); 229 | } 230 | /** 231 | * 文件复制 232 | * @param localFilePath 233 | * @param distanceFilePath 234 | * @param folderPath 235 | * @return 236 | */ 237 | public static boolean copyAs(String localFilePath,String distanceFilePath,String folderPath){ 238 | if(TextUtils.isEmpty(localFilePath) || TextUtils.isEmpty(folderPath) || TextUtils.isEmpty(distanceFilePath) || !isExist(localFilePath)){ 239 | return false; 240 | } 241 | File localFile = new File(localFilePath); 242 | File folderPathFile = new File(folderPath); 243 | File distanceFile = new File(distanceFilePath); 244 | if (!folderPathFile.exists()) 245 | folderPathFile.mkdirs(); 246 | int bytesum = 0; 247 | int byteread = 0; 248 | InputStream inStream; 249 | try { 250 | inStream = new FileInputStream(localFile); 251 | //读入原文件 252 | FileOutputStream fs = new FileOutputStream(distanceFile); 253 | byte[] buffer = new byte[1444]; 254 | while ( (byteread = inStream.read(buffer)) != -1) { 255 | bytesum += byteread; //字节数 文件大小 256 | // System.out.println(bytesum); 257 | fs.write(buffer, 0, byteread); 258 | } 259 | inStream.close(); 260 | } catch (FileNotFoundException e) { 261 | e.printStackTrace(); 262 | } catch(IOException e){ 263 | e.printStackTrace(); 264 | } 265 | return true; 266 | } 267 | } 268 | -------------------------------------------------------------------------------- /ClassicDownload/src/main/java/com/zero/cdownload/util/MD5Util.java: -------------------------------------------------------------------------------- 1 | package com.zero.cdownload.util; 2 | 3 | import android.text.TextUtils; 4 | 5 | import java.io.File; 6 | import java.io.FileInputStream; 7 | import java.io.IOException; 8 | import java.nio.MappedByteBuffer; 9 | import java.nio.channels.FileChannel; 10 | import java.security.MessageDigest; 11 | import java.security.NoSuchAlgorithmException; 12 | 13 | public class MD5Util { 14 | 15 | protected static char hexDigits[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'}; 16 | protected static MessageDigest messagedigest = null; 17 | 18 | static { 19 | try { 20 | messagedigest = MessageDigest.getInstance("MD5"); 21 | } catch (NoSuchAlgorithmException nsaex) { 22 | System.err.println(MD5Util.class.getName() + "初始化失败,MessageDigest不支持MD5Util。"); 23 | nsaex.printStackTrace(); 24 | } 25 | } 26 | 27 | public static void main(String[] args) throws IOException { 28 | long begin = System.currentTimeMillis(); 29 | 30 | File big = new File("I:/123.gif"); 31 | 32 | String md5 = getFileMD5String(big); 33 | 34 | long end = System.currentTimeMillis(); 35 | System.out.println("md5:" + md5.toUpperCase() + " time:" + ((end - begin) / 1000) + "s"); 36 | } 37 | 38 | 39 | public static String getFileMD5String(File file) throws IOException { 40 | FileInputStream in = new FileInputStream(file); 41 | FileChannel ch = in.getChannel(); 42 | MappedByteBuffer byteBuffer = ch.map(FileChannel.MapMode.READ_ONLY, 0, file.length()); 43 | messagedigest.update(byteBuffer); 44 | String md5 = bufferToHex(messagedigest.digest()); 45 | if (!TextUtils.isEmpty(md5)) { 46 | md5 = md5.toUpperCase(); 47 | } 48 | return md5; 49 | } 50 | 51 | public static String getMD5String(String s) { 52 | return getMD5String(s.getBytes()); 53 | } 54 | 55 | public static String getMD5String(byte[] bytes) { 56 | messagedigest.update(bytes); 57 | return bufferToHex(messagedigest.digest()); 58 | } 59 | 60 | private static String bufferToHex(byte bytes[]) { 61 | return bufferToHex(bytes, 0, bytes.length); 62 | } 63 | 64 | private static String bufferToHex(byte bytes[], int m, int n) { 65 | StringBuffer stringbuffer = new StringBuffer(2 * n); 66 | int k = m + n; 67 | for (int l = m; l < k; l++) { 68 | appendHexPair(bytes[l], stringbuffer); 69 | } 70 | return stringbuffer.toString(); 71 | } 72 | 73 | 74 | private static void appendHexPair(byte bt, StringBuffer stringbuffer) { 75 | char c0 = hexDigits[(bt & 0xf0) >> 4]; 76 | char c1 = hexDigits[bt & 0xf]; 77 | stringbuffer.append(c0); 78 | stringbuffer.append(c1); 79 | } 80 | 81 | public static boolean checkPassword(String password, String md5PwdStr) { 82 | String s = getMD5String(password); 83 | return s.equals(md5PwdStr); 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /ClassicDownload/src/main/java/com/zero/cdownload/util/PathUtil.java: -------------------------------------------------------------------------------- 1 | package com.zero.cdownload.util; 2 | 3 | import android.text.TextUtils; 4 | import android.util.Log; 5 | 6 | import java.io.UnsupportedEncodingException; 7 | import java.net.URLEncoder; 8 | 9 | /** 10 | * Created by zero on 2018/4/26. 11 | * 12 | * @author zero 13 | */ 14 | 15 | public class PathUtil { 16 | public static String getLocalFilePath(String netUrl, String cacheFolder, boolean needMd5Name) { 17 | if (TextUtils.isEmpty(netUrl) || TextUtils.isEmpty(cacheFolder)) { 18 | Log.e("HongLi", "in getLocalFilePath netUrl or cacheFolder is empty."); 19 | return ""; 20 | } 21 | 22 | String fileName = needMd5Name ? MD5Util.getMD5String(getUTF8(netUrl)) : FileUtil.getName(netUrl); 23 | return FileUtil.getFolderByPath(cacheFolder).getAbsolutePath() + "/" + fileName; 24 | } 25 | 26 | /** 27 | * url必须为/格式不能为\ 28 | * 29 | * @param url 30 | * @return 31 | */ 32 | public static String getUTF8(String url) { 33 | if (TextUtils.isEmpty(url)) { 34 | return ""; 35 | } 36 | String fileName = url.substring(url.lastIndexOf("/") + 1, url.length()); 37 | String filePath = url.substring(0, url.lastIndexOf("/") + 1); 38 | try { 39 | fileName = URLEncoder.encode(new String(fileName.toString().getBytes("UTF-8")), "UTF-8"); 40 | // 如果是中文空格会自动转成+ 41 | fileName = fileName.replace("+", "%20"); 42 | } catch (UnsupportedEncodingException e) { 43 | e.printStackTrace(); 44 | } 45 | return filePath + fileName; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /ClassicDownload/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | ClassicDownload 3 | 4 | -------------------------------------------------------------------------------- /ClassicDownload/src/test/java/com/zero/cdownload/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.zero.cdownload; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() throws Exception { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ### 疯狂的程序员群:186305789 2 | ### 个人兴趣网站,[zerochl接码平台](https://xinghai.party) 3 | ### 个人兴趣网站,[猿指](https://blog.xinghai.party) 4 | # ClassisDownload 5 | 基于RxJava的下载,支持线程池管理、断点续传、下载完成校验、下载过程中断、下载文件名MD5化(TaskEntity build时可选择是否使用) 6 | # 使用说明 7 | 8 | 依赖集成 9 | ``` java 10 | root gradle 添加: 11 | allprojects { 12 | repositories { 13 | ... 14 | maven { url 'https://jitpack.io' } 15 | } 16 | } 17 | 依赖添加: 18 | dependencies { 19 | implementation 'com.github.zerochl:ClassicDownload:1.0.9' 20 | } 21 | ``` 22 | 23 | * 初始化 24 | ```language_key 25 | CDownloadConfig downloadConfig = CDownloadConfig.build() 26 | 27 | .setDiskCachePath("/sdcard/Download") 28 | 29 | .setConnectConfig(ConnectConfig.build().setConnectTimeOut(10000).setReadTimeOut(20000)) 30 | 31 | .setIoThreadPoolConfig(ThreadPoolConfig.build().setCorePoolSize(4).setMaximumPoolSize(100).setKeepAliveTime(60)); 32 | 33 | CDownload.getInstance().init(downloadConfig); 34 | ``` 35 | 初始化简单易懂,看方法字面意思即可。 36 | * 使用 37 | ```language_key 38 | CDownload.getInstance().create("http://p5.qhimg.com/dr/72__/t01a362a049573708ae.png", new CDownloadListener() { 39 | @Override 40 | public void onPreStart() { 41 | Log.e("HongLi", "onPreStart"); 42 | } 43 | 44 | @Override 45 | public void onProgress(long maxSIze, long currentSize) { 46 | Log.e("HongLi", "in onProgress maxSIze:" + maxSIze + ";currentSize:" + currentSize); 47 | } 48 | 49 | @Override 50 | public void onComplete(String localFilePath) { 51 | Log.e("HongLi", "onComplete localFilePath:" + localFilePath); 52 | } 53 | 54 | @Override 55 | public void onError(String errorMessage) { 56 | Log.e("HongLi", "onError"); 57 | } 58 | 59 | @Override 60 | public void onCancel() { 61 | Log.e("HongLi", "onCancel"); 62 | } 63 | }); 64 | CDownload.getInstance().start("http://p5.qhimg.com/dr/72__/t01a362a049573708ae.png"); 65 | ``` 66 | create提供多种重载函数,同时也提供可Entity参数传入,entity支持build模式,兼容了两种风格的使用了吧。 67 | 68 | 下载的URL作为下载任务的唯一key 69 | 70 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | // JitPack Maven 3 | apply plugin: 'com.github.dcendents.android-maven' 4 | // Your Group 5 | group='com.github.zerochl' 6 | android { 7 | compileSdkVersion 26 8 | defaultConfig { 9 | applicationId "com.zero.cdownload.demo" 10 | minSdkVersion 19 11 | targetSdkVersion 22 12 | versionCode 1 13 | versionName "1.0" 14 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 15 | } 16 | buildTypes { 17 | release { 18 | minifyEnabled false 19 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 20 | } 21 | } 22 | buildToolsVersion '27.0.3' 23 | } 24 | 25 | dependencies { 26 | implementation fileTree(include: ['*.jar'], dir: 'libs') 27 | implementation 'com.android.support:appcompat-v7:26.1.0' 28 | 29 | // implementation project(':rxdownload3') 30 | 31 | // implementation 'zlc.season:rxdownload3:1.2.2' 32 | implementation project(':ClassicDownload') 33 | 34 | testImplementation 'junit:junit:4.12' 35 | androidTestImplementation 'com.android.support.test:runner:1.0.1' 36 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1' 37 | } 38 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/example/moe233/myapplicationrecycleview/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.example.moe233.myapplicationrecycleview; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumented test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() throws Exception { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.example.moe233.myapplicationrecycleview", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /app/src/main/java/com/zero/cdownload/demo/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.zero.cdownload.demo; 2 | 3 | import android.os.Bundle; 4 | import android.os.Handler; 5 | import android.support.v7.app.AppCompatActivity; 6 | import android.util.Log; 7 | 8 | import com.zero.cdownload.CDownload; 9 | import com.zero.cdownload.listener.CDownloadListener; 10 | 11 | public class MainActivity extends AppCompatActivity { 12 | 13 | 14 | @Override 15 | protected void onCreate(Bundle savedInstanceState) { 16 | super.onCreate(savedInstanceState); 17 | 18 | // if (LeakCanary.isInAnalyzerProcess(this)) { 19 | // // This process is dedicated to LeakCanary for heap analysis. 20 | // // You should not init your app in this process. 21 | // return; 22 | // } 23 | // LeakCanary.install(this); 24 | // requestPermission(MOUNT_UNMOUNT_FILESYSTEMS); 25 | // requestPermission(INTERNET); 26 | 27 | setContentView(R.layout.activity_main); 28 | 29 | new Handler().postDelayed(new Runnable() { 30 | @Override 31 | public void run() { 32 | // RxDownload.INSTANCE.delete("http://p5.qhimg.com/dr/72__/t01a362a049573708ae.png",true).subscribe(); 33 | // RxDownload.INSTANCE.clear("http://p5.qhimg.com/dr/72__/t01a362a049573708ae.png").subscribe(); 34 | // RxDownload.INSTANCE.create("http://p5.qhimg.com/dr/72__/t01a362a049573708ae.png").subscribe(new Consumer() { 35 | // @Override 36 | // public void accept(Status status) throws Exception { 37 | // Log.e("HongLi", "RxDownload status:" + status.toString()); 38 | // if (status instanceof Downloading) { 39 | //// onProgress(status.getDownloadSize(), status.getTotalSize()); 40 | // } else if (status instanceof Succeed) { 41 | //// onComplete(); 42 | // } else if (status instanceof Failed) { 43 | //// onError(((Failed) status).getThrowable()); 44 | // } 45 | // } 46 | // }); 47 | // RxDownload.INSTANCE.start("http://p5.qhimg.com/dr/72__/t01a362a049573708ae.png").subscribe(); 48 | 49 | CDownload.getInstance().create("http://xinghai.party", new CDownloadListener() { 50 | @Override 51 | public void onPreStart() { 52 | Log.e("HongLi", "onPreStart"); 53 | } 54 | 55 | @Override 56 | public void onProgress(long maxSIze, long currentSize) { 57 | Log.e("HongLi", "in onProgress maxSIze:" + maxSIze + ";currentSize:" + currentSize); 58 | } 59 | 60 | @Override 61 | public void onComplete(String localFilePath) { 62 | Log.e("HongLi", "onComplete localFilePath:" + localFilePath); 63 | } 64 | 65 | @Override 66 | public void onError(String errorMessage) { 67 | Log.e("HongLi", "onError errorMessage:" + errorMessage); 68 | } 69 | 70 | @Override 71 | public void onCancel() { 72 | Log.e("HongLi", "onCancel"); 73 | } 74 | }); 75 | CDownload.getInstance().start("http://xinghai.party"); 76 | } 77 | }, 0); 78 | 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /app/src/main/java/com/zero/cdownload/demo/MyApplication.java: -------------------------------------------------------------------------------- 1 | package com.zero.cdownload.demo; 2 | 3 | import android.app.Application; 4 | 5 | import com.zero.cdownload.CDownload; 6 | import com.zero.cdownload.config.CDownloadConfig; 7 | import com.zero.cdownload.config.ConnectConfig; 8 | import com.zero.cdownload.config.ThreadPoolConfig; 9 | 10 | /** 11 | * @author caizhixing 12 | * @date 3/15/2018. 13 | */ 14 | 15 | public class MyApplication extends Application { 16 | 17 | @Override 18 | public void onCreate() { 19 | super.onCreate(); 20 | CDownloadConfig downloadConfig = CDownloadConfig.build() 21 | .setDiskCachePath("/sdcard/mimikko/download") 22 | .setConnectConfig(ConnectConfig.build().setConnectTimeOut(10000).setReadTimeOut(20000)) 23 | .setIoThreadPoolConfig(ThreadPoolConfig.build().setCorePoolSize(4).setMaximumPoolSize(100).setKeepAliveTime(60)); 24 | 25 | CDownload.getInstance().init(downloadConfig); 26 | } 27 | } 28 | 29 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 12 | 13 | 19 | 22 | 25 | 26 | 27 | 28 | 34 | 35 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 | 50 | 55 | 60 | 65 | 70 | 75 | 80 | 85 | 90 | 95 | 100 | 105 | 110 | 115 | 120 | 125 | 130 | 135 | 140 | 145 | 150 | 155 | 160 | 165 | 170 | 171 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /app/src/main/res/layout/item.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zerochl/ClassicDownload/abb1f7da600deeb0991f962cad65b00323af15ff/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zerochl/ClassicDownload/abb1f7da600deeb0991f962cad65b00323af15ff/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zerochl/ClassicDownload/abb1f7da600deeb0991f962cad65b00323af15ff/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zerochl/ClassicDownload/abb1f7da600deeb0991f962cad65b00323af15ff/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zerochl/ClassicDownload/abb1f7da600deeb0991f962cad65b00323af15ff/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zerochl/ClassicDownload/abb1f7da600deeb0991f962cad65b00323af15ff/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/psb.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zerochl/ClassicDownload/abb1f7da600deeb0991f962cad65b00323af15ff/app/src/main/res/mipmap-xhdpi/psb.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zerochl/ClassicDownload/abb1f7da600deeb0991f962cad65b00323af15ff/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zerochl/ClassicDownload/abb1f7da600deeb0991f962cad65b00323af15ff/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zerochl/ClassicDownload/abb1f7da600deeb0991f962cad65b00323af15ff/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zerochl/ClassicDownload/abb1f7da600deeb0991f962cad65b00323af15ff/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | My Application RecycleView 3 | 4 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /app/src/test/java/com/example/moe233/myapplicationrecycleview/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.example.moe233.myapplicationrecycleview; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() throws Exception { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | 5 | repositories { 6 | google() 7 | jcenter() 8 | } 9 | dependencies { 10 | classpath 'com.android.tools.build:gradle:3.5.3' 11 | 12 | classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.0' 13 | classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5' 14 | 15 | // classpath 'com.novoda:bintray-release:0.8.1' 16 | 17 | // NOTE: Do not place your application dependencies here; they belong 18 | // in the individual module build.gradle files 19 | } 20 | } 21 | 22 | //apply plugin: 'com.novoda.bintray-release' 23 | allprojects { 24 | repositories { 25 | maven { url 'https://jitpack.io' } 26 | google() 27 | jcenter() 28 | } 29 | tasks.withType(Javadoc) { 30 | options.addStringOption('Xdoclint:none', '-quiet') 31 | options.addStringOption('encoding', 'UTF-8') 32 | } 33 | } 34 | 35 | task clean(type: Delete) { 36 | delete rootProject.buildDir 37 | } 38 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zerochl/ClassicDownload/abb1f7da600deeb0991f962cad65b00323af15ff/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Mon May 11 17:26:06 CST 2020 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # Attempt to set APP_HOME 46 | # Resolve links: $0 may be a link 47 | PRG="$0" 48 | # Need this for relative symlinks. 49 | while [ -h "$PRG" ] ; do 50 | ls=`ls -ld "$PRG"` 51 | link=`expr "$ls" : '.*-> \(.*\)$'` 52 | if expr "$link" : '/.*' > /dev/null; then 53 | PRG="$link" 54 | else 55 | PRG=`dirname "$PRG"`"/$link" 56 | fi 57 | done 58 | SAVED="`pwd`" 59 | cd "`dirname \"$PRG\"`/" >/dev/null 60 | APP_HOME="`pwd -P`" 61 | cd "$SAVED" >/dev/null 62 | 63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 64 | 65 | # Determine the Java command to use to start the JVM. 66 | if [ -n "$JAVA_HOME" ] ; then 67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 68 | # IBM's JDK on AIX uses strange locations for the executables 69 | JAVACMD="$JAVA_HOME/jre/sh/java" 70 | else 71 | JAVACMD="$JAVA_HOME/bin/java" 72 | fi 73 | if [ ! -x "$JAVACMD" ] ; then 74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 75 | 76 | Please set the JAVA_HOME variable in your environment to match the 77 | location of your Java installation." 78 | fi 79 | else 80 | JAVACMD="java" 81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 82 | 83 | Please set the JAVA_HOME variable in your environment to match the 84 | location of your Java installation." 85 | fi 86 | 87 | # Increase the maximum file descriptors if we can. 88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 89 | MAX_FD_LIMIT=`ulimit -H -n` 90 | if [ $? -eq 0 ] ; then 91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 92 | MAX_FD="$MAX_FD_LIMIT" 93 | fi 94 | ulimit -n $MAX_FD 95 | if [ $? -ne 0 ] ; then 96 | warn "Could not set maximum file descriptor limit: $MAX_FD" 97 | fi 98 | else 99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 100 | fi 101 | fi 102 | 103 | # For Darwin, add options to specify how the application appears in the dock 104 | if $darwin; then 105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 106 | fi 107 | 108 | # For Cygwin, switch paths to Windows format before running java 109 | if $cygwin ; then 110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 112 | JAVACMD=`cygpath --unix "$JAVACMD"` 113 | 114 | # We build the pattern for arguments to be converted via cygpath 115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 116 | SEP="" 117 | for dir in $ROOTDIRSRAW ; do 118 | ROOTDIRS="$ROOTDIRS$SEP$dir" 119 | SEP="|" 120 | done 121 | OURCYGPATTERN="(^($ROOTDIRS))" 122 | # Add a user-defined pattern to the cygpath arguments 123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 125 | fi 126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 127 | i=0 128 | for arg in "$@" ; do 129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 131 | 132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 134 | else 135 | eval `echo args$i`="\"$arg\"" 136 | fi 137 | i=$((i+1)) 138 | done 139 | case $i in 140 | (0) set -- ;; 141 | (1) set -- "$args0" ;; 142 | (2) set -- "$args0" "$args1" ;; 143 | (3) set -- "$args0" "$args1" "$args2" ;; 144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 150 | esac 151 | fi 152 | 153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 154 | function splitJvmOpts() { 155 | JVM_OPTS=("$@") 156 | } 157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 159 | 160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 161 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app', ':ClassicDownload' 2 | --------------------------------------------------------------------------------