Skip to content
This repository has been archived by the owner on Dec 7, 2019. It is now read-only.

start of filesystem impl conversion to kotlin #358

Open
wants to merge 7 commits into
base: feature/kotlin_conversion
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view

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 {
Copy link
Contributor

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!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done!

override fun deleteAll(path: String): Observable<Boolean> {
return Observable.fromCallable {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can lift it to assignment!

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here it can be private I think!

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can lift it to assignment!

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can lift it to assignment!

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can lift it to assignment!

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All these vals can be private and by lazy :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can lift it to assignment! Similarly on the following methods!

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can lift it to assignment!

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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>