com.avito.android.critical_path.internal.CriticalPathReport.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of critical-path Show documentation
Show all versions of critical-path Show documentation
Collection of infrastructure libraries and gradle plugins of Avito Android project
package com.avito.android.critical_path.internal
import com.google.gson.GsonBuilder
import com.google.gson.reflect.TypeToken
import java.io.File
internal class CriticalPathReport(
private val report: File
) {
private val gson = GsonBuilder()
.create()
fun write(records: List) {
ensureReportExists()
report.writeText(gson.toJson(records))
}
fun read(): List {
val type = object : TypeToken>() {}.type
return gson.fromJson(report.bufferedReader(), type)
}
private fun ensureReportExists() {
if (!report.exists()) {
report.parentFile.mkdirs()
report.createNewFile()
}
}
}