Skip to content

Commit

Permalink
commit code.
Browse files Browse the repository at this point in the history
  • Loading branch information
ssseasonnn committed Aug 18, 2017
1 parent d4ce3f0 commit 926c7d7
Show file tree
Hide file tree
Showing 19 changed files with 231 additions and 70 deletions.
16 changes: 8 additions & 8 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -103,17 +103,17 @@
excluding those notices that do not pertain to any part of
the Derivative Works; and

(d) If the Work includes a "NOTICE" text file as part of its
(d) If the Work includes a "NOTICE" text fileName as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
within such NOTICE fileName, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
of the following places: within a NOTICE text fileName distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
of the NOTICE fileName are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
Expand All @@ -138,7 +138,7 @@
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
origin of the Work and reproducing the content of the NOTICE fileName.

7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Expand Down Expand Up @@ -181,15 +181,15 @@
boilerplate notice, with the fields enclosed by brackets "{}"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
comment syntax for the fileName format. We also recommend that a
fileName or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright {yyyy} {name of copyright owner}

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
you may not use this fileName except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0
Expand Down
16 changes: 8 additions & 8 deletions README.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,15 @@ RxDownload rxDownload = RxDownload.getInstance(context)

- ```xxDownload(String url)```

When only pass url, will automatically get the file name from the server
When only pass url, will automatically get the fileName name from the server

- ```xxDownload(String url, String saveName)```

You can also specify the name of the saved file
You can also specify the name of the saved fileName

- ```xxDownload(String url,String saveName,String savePath)```

You can also specify the file name and save the path manually
You can also specify the fileName name and save the path manually

- ```xxDownload(DownloadBean bean)```

Expand Down Expand Up @@ -279,18 +279,18 @@ mRxDownload.getTotalDownloadRecords()
});
```

### Get the download file
### Get the download fileName

Get the download file
Get the download fileName

```java
//Use url to get
File[] files = rxDownload.getRealFiles(url);
if (files != null) {
File file = files[0];
File fileName = files[0];
}
//Use saveName and savePath to get
File file = rxDownload.getRealFiles(saveName,savePath)[0];
File fileName = rxDownload.getRealFiles(saveName,savePath)[0];
```

### About me
Expand All @@ -309,7 +309,7 @@ Gmail: ssseasonnn@gmail.com
> Copyright 2016 Season.Zlc
>
> Licensed under the Apache License, Version 2.0 (the "License");
> you may not use this file except in compliance with the License.
> you may not use this fileName except in compliance with the License.
> You may obtain a copy of the License at
>
> http://www.apache.org/licenses/LICENSE-2.0
Expand Down
2 changes: 1 addition & 1 deletion app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# By default, the flags in this fileName are appended to flags specified
# in D:\Application\Android-Sdk/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
Expand Down
6 changes: 3 additions & 3 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi

# Increase the maximum file descriptors if we can.
# Increase the maximum fileName descriptors if we can.
if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
MAX_FD_LIMIT=`ulimit -H -n`
if [ $? -eq 0 ] ; then
Expand All @@ -93,10 +93,10 @@ if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
fi
ulimit -n $MAX_FD
if [ $? -ne 0 ] ; then
warn "Could not set maximum file descriptor limit: $MAX_FD"
warn "Could not set maximum fileName descriptor limit: $MAX_FD"
fi
else
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
warn "Could not query maximum fileName descriptor limit: $MAX_FD_LIMIT"
fi
fi

Expand Down
2 changes: 1 addition & 1 deletion rxdownload2/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# By default, the flags in this fileName are appended to flags specified
# in D:\Application\Android-Sdk/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
Expand Down
4 changes: 2 additions & 2 deletions rxdownload3/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# By default, the flags in this fileName are appended to flags specified
# in /Users/season/develop/sdk/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
Expand All @@ -21,5 +21,5 @@
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
# hide the original source fileName name.
#-renamesourcefileattribute SourceFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package zlc.season.rxdownload3.core

import android.os.Environment


object DownloadConfig {
var defaultSavePath = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).path
var retryCount = 3
var threadCount = 3
var perSize: Int = 5 * 1024 //KB

}
Original file line number Diff line number Diff line change
@@ -1,22 +1,14 @@
package zlc.season.rxdownload3.core

import android.os.Environment.*
import io.reactivex.Observable
import io.reactivex.plugins.RxJavaPlugins
import io.reactivex.schedulers.Schedulers
import zlc.season.rxdownload3.helper.Logger
import zlc.season.rxdownload3.http.RetrofitApi
import zlc.season.rxdownload3.http.RetrofitClient
import java.io.InterruptedIOException
import java.net.SocketException


class DownloadCore {
var api = RetrofitClient.get().create(RetrofitApi::class.java)
var defaultSavePath = getExternalStoragePublicDirectory(DIRECTORY_DOWNLOADS).path
var retryCount = 3
var threadCount = 3


init {
initRxJavaPlugin()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@ data class DownloadMission(
val savePath: String = "") : Mission {


override fun provideTag(): String {
override fun tag(): String {
return url
}

override fun provideUrl(): String {
override fun url(): String {
return url
}

override fun provideFileName(): String {
override fun fileName(): String {
return fileName
}

override fun provideSavePath(): String {
override fun savePath(): String {
return savePath
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package zlc.season.rxdownload3.core

import io.reactivex.Flowable


interface DownloadType {
fun download(): Flowable<DownloadStatus>
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package zlc.season.rxdownload3.core


interface Mission {
fun provideTag(): String
fun provideUrl(): String
fun provideFileName(): String
fun provideSavePath(): String
fun tag(): String
fun url(): String
fun fileName(): String
fun savePath(): String
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ object MissionBox {
val processorMap = mutableMapOf<String, Processor<DownloadStatus>>()

fun produce(mission: Mission): Observable<DownloadStatus> {
var processor = processorMap[mission.provideTag()]
var processor = processorMap[mission.tag()]
if (processor == null) {
processor = BehaviorProcessor.create<DownloadStatus>().toSerialized()
processorMap[mission.provideTag()] = processor
processorMap[mission.tag()] = processor
}

queue.put(MissionWrapper(mission, processor))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,45 @@
package zlc.season.rxdownload3.core

import io.reactivex.Maybe
import io.reactivex.processors.FlowableProcessor
import zlc.season.rxdownload3.http.HttpProcessor


class MissionWrapper(val mission: Mission, val processor: FlowableProcessor<DownloadStatus>) {

var isSupportRange: Boolean = false
var isFileChange: Boolean = false

val rangeSupport: Boolean = false
val fileChanged: Boolean = false
var lastModify: Long = 0L

val lastModify: String = ""
lateinit var realFileName: String

val threads: Int = 3
val perSize: Int = 5 * 1024 //KB
lateinit var downloadType: DownloadType

lateinit var tmpFile: TmpFile
lateinit var targetFile: TargetFile

init {


processor.onNext(DownloadStatus(0))
}

fun start() {
fun createDownloadType() {
if (isSupportRange) {
downloadType = NormalDownload(this)
} else {
downloadType = RangeDownload()
}
}

fun start() {
Maybe.just(1)
.flatMap { HttpProcessor.checkUrl(this) }
.doOnSuccess { createDownloadType() }
.toFlowable()
.flatMap { downloadType.download() }
.subscribe({ println("next") }, { println("error") }, { println("complete") })
}


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package zlc.season.rxdownload3.core

import io.reactivex.BackpressureStrategy
import io.reactivex.Flowable
import io.reactivex.FlowableEmitter
import okhttp3.ResponseBody
import retrofit2.Response
import zlc.season.rxdownload3.http.HttpProcessor


class NormalDownload(val missionWrapper: MissionWrapper) : DownloadType {

override fun download(): Flowable<DownloadStatus> {
return HttpProcessor.download(missionWrapper)
.flatMap { resp ->

Flowable.just(DownloadStatus(1))
}
}

fun saveFile(resp: Response<ResponseBody>): Flowable<DownloadStatus> {
return Flowable.create({ emitter ->

}, BackpressureStrategy.LATEST)
}

fun realSave(emitter: FlowableEmitter<DownloadStatus>, resp: Response<ResponseBody>) {

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package zlc.season.rxdownload3.core

import io.reactivex.Flowable


class RangeDownload:DownloadType {
override fun download(): Flowable<DownloadStatus> {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,30 @@
package zlc.season.rxdownload3.core

import io.reactivex.FlowableEmitter
import okhttp3.ResponseBody
import retrofit2.Response
import java.io.File
import java.io.InputStream
import java.io.OutputStream


class TargetFile {
lateinit var file: File

fun save(emitter: FlowableEmitter<DownloadStatus>, response: Response<ResponseBody>) {
var fileInStream: InputStream
var fileOutSteam: OutputStream

val buffer: ByteArray = kotlin.ByteArray(8)


val respBody = response.body()
if (respBody == null) {
emitter.onError(RuntimeException("body is null"))
return
}

fileInStream = respBody.byteStream()

}
}
Loading

0 comments on commit 926c7d7

Please sign in to comment.