com.lsd.core.properties.PropertiesLoader.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of lsd-core Show documentation
Show all versions of lsd-core Show documentation
A library used to generate living sequence diagrams
The newest version!
package com.lsd.core.properties
import java.io.IOException
import java.io.InputStream
import java.util.*
import java.util.function.Consumer
class PropertiesLoader(
private val fileName: String,
private val defaults: Properties
) {
fun load(): Properties {
val inputStream = javaClass.getResourceAsStream("/$fileName")
val properties = Properties(defaults)
Optional.ofNullable(inputStream).ifPresent(loadInto(properties))
properties.putAll(System.getProperties())
return properties
}
private fun loadInto(properties: Properties): Consumer {
return Consumer { stream: InputStream ->
try {
properties.load(stream)
} catch (e: IOException) {
println("Failed to load properties file, falling back to default values. Error: [${e.message}]")
}
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy