ConfigurationLoader

public final class ConfigurationLoader<T extends Object>(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
public ConfigurationLoader<T> ConfigurationLoader<T extends Any>(String subDirectory, String fileName, Codec<T> codec)

Configuration loader for a configuration file using codec.

public ConfigurationLoader<T> ConfigurationLoader<T extends Any>(Path configurationFile, Codec<T> codec)

Types

Link copied to clipboard
public class Companion

Properties

Link copied to clipboard
private final Codec<T> codec
Link copied to clipboard
Link copied to clipboard
private final Path configurationFile

Functions

Link copied to clipboard
public final Codec<T> getCodec()
Link copied to clipboard
public final Path getConfigurationFile()
Link copied to clipboard
public final T loadConfiguration()

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

Link copied to clipboard
public final T loadOrSaveConfiguration(Function0<T> defaultSupplier)

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
public final Unit saveConfiguration(T configuration)

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