-
Notifications
You must be signed in to change notification settings - Fork 305
start of filesystem impl conversion to kotlin #358
base: feature/kotlin_conversion
Are you sure you want to change the base?
Changes from 2 commits
b0a6bc2
9269b63
0355e3e
fd6a8c7
76c8582
f9b65d0
320f5c3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.nytimes.android.external.fs3 | ||
|
||
import com.nytimes.android.external.fs3.filesystem.FileSystem | ||
import com.nytimes.android.external.store3.base.DiskAllErase | ||
import io.reactivex.Observable | ||
|
||
|
||
class FSAllEraser(internal val fileSystem: FileSystem) : DiskAllErase { | ||
override fun deleteAll(path: String): Observable<Boolean> { | ||
return Observable.fromCallable { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can lift it to assignment! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done! |
||
fileSystem.deleteAll(path) | ||
true | ||
} | ||
} | ||
} |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.nytimes.android.external.fs3 | ||
|
||
import com.nytimes.android.external.fs3.filesystem.FileSystem | ||
import com.nytimes.android.external.store3.base.DiskWrite | ||
|
||
import io.reactivex.Single | ||
import okio.BufferedSource | ||
|
||
/** | ||
* FSReader is used when persisting to file system | ||
* PathResolver will be used in creating file system paths based on cache keys. | ||
* Make sure to have keys containing same data resolve to same "path" | ||
* @param <T> key type | ||
</T> */ | ||
open class FSWriter<T>(internal val fileSystem: FileSystem, internal val pathResolver: PathResolver<T>) : DiskWrite<BufferedSource, T> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here it can be private I think! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done! |
||
|
||
override fun write(key: T, data: BufferedSource): Single<Boolean> { | ||
return Single.fromCallable { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can lift it to assignment! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done! |
||
fileSystem.write(pathResolver.resolve(key), data) | ||
true | ||
} | ||
} | ||
} |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.nytimes.android.external.fs3 | ||
|
||
import com.nytimes.android.external.fs3.filesystem.FileSystem | ||
import com.nytimes.android.external.store3.base.RecordProvider | ||
import com.nytimes.android.external.store3.base.RecordState | ||
import com.nytimes.android.external.store3.base.impl.BarCode | ||
|
||
import java.util.concurrent.TimeUnit | ||
import javax.inject.Inject | ||
|
||
class RecordPersister @Inject | ||
constructor(fileSystem: FileSystem, | ||
private val expirationDuration: Long, | ||
private val expirationUnit: TimeUnit) : SourcePersister(fileSystem), RecordProvider<BarCode> { | ||
|
||
override fun getRecordState(barCode: BarCode): RecordState { | ||
return sourceFileReader.getRecordState(barCode, expirationUnit, expirationDuration) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can lift it to assignment! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done! |
||
} | ||
|
||
companion object { | ||
|
||
fun create(fileSystem: FileSystem, | ||
expirationDuration: Long, | ||
expirationUnit: TimeUnit): RecordPersister { | ||
return RecordPersister(fileSystem, expirationDuration, expirationUnit) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can lift it to assignment! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done! |
||
} | ||
} | ||
} |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package com.nytimes.android.external.fs3 | ||
|
||
|
||
import com.nytimes.android.external.fs3.filesystem.FileSystem | ||
import com.nytimes.android.external.store3.base.AllPersister | ||
import com.nytimes.android.external.store3.base.impl.BarCode | ||
|
||
import java.io.FileNotFoundException | ||
import javax.inject.Inject | ||
|
||
import io.reactivex.Maybe | ||
import io.reactivex.Observable | ||
import io.reactivex.Single | ||
import okio.BufferedSource | ||
|
||
class SourceAllPersister @Inject | ||
constructor(fileSystem: FileSystem) : AllPersister<BufferedSource, BarCode> { | ||
|
||
internal val sourceFileAllReader: FSAllReader | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All these There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done! |
||
internal val sourceFileAllEraser: FSAllEraser | ||
|
||
internal val sourceFileReader: FSReader<BarCode> | ||
internal val sourceFileWriter: FSWriter<BarCode> | ||
|
||
init { | ||
sourceFileAllReader = FSAllReader(fileSystem) | ||
sourceFileAllEraser = FSAllEraser(fileSystem) | ||
sourceFileReader = FSReader(fileSystem, BarCodeReadAllPathResolver()) | ||
sourceFileWriter = FSWriter(fileSystem, BarCodeReadAllPathResolver()) | ||
} | ||
|
||
@Throws(FileNotFoundException::class) | ||
override fun readAll(path: String): Observable<BufferedSource> { | ||
return sourceFileAllReader.readAll(path) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can lift it to assignment! Similarly on the following methods! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done! |
||
} | ||
|
||
override fun deleteAll(path: String): Observable<Boolean> { | ||
return sourceFileAllEraser.deleteAll(path) | ||
} | ||
|
||
override fun read(barCode: BarCode): Maybe<BufferedSource> { | ||
return sourceFileReader.read(barCode) | ||
} | ||
|
||
override fun write(barCode: BarCode, data: BufferedSource): Single<Boolean> { | ||
return sourceFileWriter.write(barCode, data) | ||
} | ||
|
||
companion object { | ||
|
||
fun create(fileSystem: FileSystem): SourceAllPersister { | ||
return SourceAllPersister(fileSystem) | ||
} | ||
} | ||
} |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.nytimes.android.external.fs3 | ||
|
||
import com.nytimes.android.external.fs3.filesystem.FileSystem | ||
import com.nytimes.android.external.store3.base.DiskRead | ||
import com.nytimes.android.external.store3.base.RecordState | ||
import com.nytimes.android.external.store3.base.impl.BarCode | ||
import okio.BufferedSource | ||
import java.util.concurrent.TimeUnit | ||
|
||
class SourceFileReader @JvmOverloads constructor(fileSystem: FileSystem, pathResolver: PathResolver<BarCode> = BarCodePathResolver()) : FSReader<BarCode>(fileSystem, pathResolver), DiskRead<BufferedSource, BarCode> { | ||
|
||
fun getRecordState(barCode: BarCode, | ||
expirationUnit: TimeUnit, | ||
expirationDuration: Long): RecordState { | ||
return fileSystem.getRecordState(expirationUnit, expirationDuration, SourcePersister.pathForBarcode(barCode)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can lift it to assignment! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done! |
||
} | ||
} |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.nytimes.android.external.fs3 | ||
|
||
import com.nytimes.android.external.fs3.filesystem.FileSystem | ||
import com.nytimes.android.external.store3.base.DiskWrite | ||
import com.nytimes.android.external.store3.base.impl.BarCode | ||
|
||
import okio.BufferedSource | ||
|
||
class SourceFileWriter @JvmOverloads constructor(fileSystem: FileSystem, pathResolver: PathResolver<BarCode> = BarCodePathResolver()) : FSWriter<BarCode>(fileSystem, pathResolver), DiskWrite<BufferedSource, BarCode> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if this was intended to have package level visibility in the previous implementation, put it can be private I think!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done!