ConfigurationLoader

class ConfigurationLoader<T>(val configurationFile: Path, val codec: Codec<T>)(source)

Configuration loader for a configuration file using codec.

Parameters

configurationFile

The configuration file path

codec

The codec used to serialize and deserialize the configuration

See also

Constructors

Link copied to clipboard
constructor(subDirectory: String, fileName: String, codec: Codec<T>)

Configuration loader for a configuration file using codec.

constructor(configurationFile: Path, codec: Codec<T>)

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
val codec: Codec<T>
Link copied to clipboard

Functions

Link copied to clipboard

Reads the configuration from configurationFile. This doesn't handle IO errors (like inaccessible file), malformed JSON, or decoding failures.

Link copied to clipboard
fun loadOrSaveConfiguration(defaultSupplier: () -> T): T

Reads the configuration from configurationFile if it exists. If it doesn't exist, it returns the supplied default configuration, and writes it to configurationFile. This doesn't handle IO errors (like inaccessible file), malformed JSON, or encoding and decoding failures.

Link copied to clipboard
fun saveConfiguration(configuration: T)

Writes the given configuration to configurationFile. This doesn't handle IO errors (like inaccessible file), or encoding failures.