mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-13 03:54:06 +09:00
com.torvald → net.torvald
Former-commit-id: 375604da8a20a6ba7cd0a8d05a44add02b2d04f4 Former-commit-id: 287287c5920b07618174d7a7573f049d350ded66
This commit is contained in:
36
src/net/torvald/JsonFetcher.kt
Normal file
36
src/net/torvald/JsonFetcher.kt
Normal file
@@ -0,0 +1,36 @@
|
||||
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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user