Skip to content

Commit

Permalink
fix bug (if json is empty)
Browse files Browse the repository at this point in the history
  • Loading branch information
Abbas committed Oct 20, 2018
1 parent 4a4c3f6 commit 97e26e0
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.0'
classpath 'com.android.tools.build:gradle:3.2.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@ internal class EngineModel(private val appContext: Context,
private val scope: String) {

private val path = appContext.getPath()
private val firstDataJson = "{is:true}"

internal fun makeDatabase(): Boolean {
return File(path + scope).mkdir()
}

internal fun makeDocument(name: String): Boolean {
val file = File("$path$scope/$name.json")
return writeJSON(file, JSONObject("{is:true}"))
return writeJSON(file, JSONObject(firstDataJson))
}

internal fun isDatabase(): Boolean {
Expand Down Expand Up @@ -61,10 +62,13 @@ internal class EngineModel(private val appContext: Context,

fileInputStream.read(buffer)

val value = String(buffer, Charsets.UTF_8)
var value = String(buffer, Charsets.UTF_8)

fileInputStream.close()

if (value.isEmpty())
value = firstDataJson

return JSONObject(value)
}
}
1 change: 0 additions & 1 deletion sample/src/main/java/com/dfmabbas/sample/KotlinSample.kt
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,5 @@ class KotlinSample : Fragment() {

// reactor.remove("age", 0)
// reactor.clearAll()

}
}

0 comments on commit 97e26e0

Please sign in to comment.