mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-15 16:16:10 +09:00
Former-commit-id: 375604da8a20a6ba7cd0a8d05a44add02b2d04f4 Former-commit-id: 287287c5920b07618174d7a7573f049d350ded66
37 lines
958 B
Kotlin
37 lines
958 B
Kotlin
package net.torvald
|
|
|
|
import com.google.gson.JsonObject
|
|
import com.google.gson.JsonParser
|
|
|
|
import java.io.IOException
|
|
import java.nio.file.FileSystems
|
|
import java.nio.file.Files
|
|
import java.util.ArrayList
|
|
import java.util.function.Consumer
|
|
|
|
/**
|
|
* Created by minjaesong on 16-02-15.
|
|
*/
|
|
object JsonFetcher {
|
|
|
|
private var jsonString: StringBuffer? = null
|
|
|
|
@Throws(IOException::class)
|
|
fun readJson(jsonFilePath: String): JsonObject {
|
|
jsonString = StringBuffer() // reset buffer every time it called
|
|
readJsonFileAsString(jsonFilePath)
|
|
|
|
val jsonParser = JsonParser()
|
|
val jsonObj = jsonParser.parse(jsonString!!.toString()).asJsonObject
|
|
|
|
return jsonObj
|
|
}
|
|
|
|
@Throws(IOException::class)
|
|
private fun readJsonFileAsString(path: String) {
|
|
Files.lines(FileSystems.getDefault().getPath(path)).forEach(
|
|
{ jsonString!!.append(it) }
|
|
) // JSON does not require line break
|
|
}
|
|
}
|