Package de.exlll.configlib
Class YamlConfigurations
java.lang.Object
de.exlll.configlib.YamlConfigurations
This class contains convenience methods for reading, writing, loading, saving,
and updating configurations.
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> TLoads a configuration of the given type from the specified YAML file using aYamlConfigurationPropertiesobject with default values.static <T> Tload(Path configurationFile, Class<T> configurationType, YamlConfigurationProperties properties) Loads a configuration of the given type from the specified YAML file using the givenYamlConfigurationPropertiesobject.static <T> Tload(Path configurationFile, Class<T> configurationType, Consumer<YamlConfigurationProperties.Builder<?>> propertiesConfigurer) Loads a configuration of the given type from the specified YAML file using aYamlConfigurationPropertiesobject that is built by a builder.static <T> Tread(InputStream inputStream, Class<T> configurationType) Reads a configuration of the given type from the given input stream using aYamlConfigurationPropertiesobject with default values.static <T> Tread(InputStream inputStream, Class<T> configurationType, YamlConfigurationProperties properties) Reads a configuration of the given type from the given input stream using the givenYamlConfigurationPropertiesobject.static <T> Tread(InputStream inputStream, Class<T> configurationType, Consumer<YamlConfigurationProperties.Builder<?>> propertiesConfigurer) Reads a configuration of the given type from the given input stream using aYamlConfigurationPropertiesobject that is built by a builder.static <T> voidSaves a configuration of the given type to the specified YAML file using aYamlConfigurationPropertiesobject with default values.static <T> voidsave(Path configurationFile, Class<T> configurationType, T configuration, YamlConfigurationProperties properties) Saves a configuration of the given type to the specified YAML file using the givenYamlConfigurationPropertiesobject.static <T> voidsave(Path configurationFile, Class<T> configurationType, T configuration, Consumer<YamlConfigurationProperties.Builder<?>> propertiesConfigurer) Saves a configuration of the given type to the specified YAML file using aYamlConfigurationPropertiesobject that is built by a builder.static <T> TUpdates a YAML configuration file with a configuration of the given type using aYamlConfigurationPropertiesobject with default values.static <T> Tupdate(Path configurationFile, Class<T> configurationType, YamlConfigurationProperties properties) Updates a YAML configuration file with a configuration of the given type using the givenYamlConfigurationPropertiesobject.static <T> Tupdate(Path configurationFile, Class<T> configurationType, Consumer<YamlConfigurationProperties.Builder<?>> propertiesConfigurer) Updates a YAML configuration file with a configuration of the given type using aYamlConfigurationPropertiesobject that is built by a builder.static <T> voidwrite(OutputStream outputStream, Class<T> configurationType, T configuration) Writes a configuration instance to the given output stream using aYamlConfigurationPropertiesobject with default values.static <T> voidwrite(OutputStream outputStream, Class<T> configurationType, T configuration, YamlConfigurationProperties properties) Writes a configuration instance to the given output stream using the givenYamlConfigurationPropertiesobject.static <T> voidwrite(OutputStream outputStream, Class<T> configurationType, T configuration, Consumer<YamlConfigurationProperties.Builder<?>> propertiesConfigurer) Writes a configuration instance to the given output stream using aYamlConfigurationPropertiesobject that is built by a builder.
-
Method Details
-
load
Loads a configuration of the given type from the specified YAML file using aYamlConfigurationPropertiesobject with default values.- Type Parameters:
T- the configuration type- Parameters:
configurationFile- the file the configuration is loaded fromconfigurationType- the type of configuration- Returns:
- a newly created configuration initialized with values taken from the configuration file
- Throws:
de.exlll.configlib.ConfigurationException- if the configuration cannot be deserializedIllegalArgumentException- if the file does not exist or is not a regular fileNullPointerException- if any parameter is nullRuntimeException- if reading the configuration throws an exception- See Also:
-
load
public static <T> T load(Path configurationFile, Class<T> configurationType, Consumer<YamlConfigurationProperties.Builder<?>> propertiesConfigurer) Loads a configuration of the given type from the specified YAML file using aYamlConfigurationPropertiesobject that is built by a builder. The builder is initialized with default values and can be configured by thepropertiesConfigurer.- Type Parameters:
T- the configuration type- Parameters:
configurationFile- the file the configuration is loaded fromconfigurationType- the type of configurationpropertiesConfigurer- the consumer used to configure the builder- Returns:
- a newly created configuration initialized with values taken from the configuration file
- Throws:
de.exlll.configlib.ConfigurationException- if the configuration cannot be deserializedIllegalArgumentException- if the file does not exist or is not a regular fileNullPointerException- if any parameter is nullRuntimeException- if reading the configuration throws an exception- See Also:
-
load
public static <T> T load(Path configurationFile, Class<T> configurationType, YamlConfigurationProperties properties) Loads a configuration of the given type from the specified YAML file using the givenYamlConfigurationPropertiesobject.- Type Parameters:
T- the configuration type- Parameters:
configurationFile- the file the configuration is loaded fromconfigurationType- the type of configurationproperties- the configuration properties- Returns:
- a newly created configuration initialized with values taken from the configuration file
- Throws:
de.exlll.configlib.ConfigurationException- if the configuration cannot be deserializedIllegalArgumentException- if the file does not exist or is not a regular fileNullPointerException- if any parameter is nullRuntimeException- if reading the configuration throws an exception- See Also:
-
read
Reads a configuration of the given type from the given input stream using aYamlConfigurationPropertiesobject with default values.- Type Parameters:
T- the configuration type- Parameters:
inputStream- the input stream the configuration is read fromconfigurationType- the type of configuration- Returns:
- a newly created configuration initialized with values read from
inputStream - Throws:
de.exlll.configlib.ConfigurationException- if the configuration cannot be deserializedNullPointerException- if any parameter is nullRuntimeException- if reading the configuration throws an exception- See Also:
-
read
public static <T> T read(InputStream inputStream, Class<T> configurationType, Consumer<YamlConfigurationProperties.Builder<?>> propertiesConfigurer) Reads a configuration of the given type from the given input stream using aYamlConfigurationPropertiesobject that is built by a builder. The builder is initialized with default values and can be configured by thepropertiesConfigurer.- Type Parameters:
T- the configuration type- Parameters:
inputStream- the input stream the configuration is read fromconfigurationType- the type of configurationpropertiesConfigurer- the consumer used to configure the builder- Returns:
- a newly created configuration initialized with values read from
inputStream - Throws:
de.exlll.configlib.ConfigurationException- if the configuration cannot be deserializedNullPointerException- if any parameter is nullRuntimeException- if reading the configuration throws an exception- See Also:
-
read
public static <T> T read(InputStream inputStream, Class<T> configurationType, YamlConfigurationProperties properties) Reads a configuration of the given type from the given input stream using the givenYamlConfigurationPropertiesobject.- Type Parameters:
T- the configuration type- Parameters:
inputStream- the input stream the configuration is read fromconfigurationType- the type of configurationproperties- the configuration properties- Returns:
- a newly created configuration initialized with values read from
inputStream - Throws:
de.exlll.configlib.ConfigurationException- if the configuration cannot be deserializedNullPointerException- if any parameter is nullRuntimeException- if reading the configuration throws an exception- See Also:
-
update
Updates a YAML configuration file with a configuration of the given type using aYamlConfigurationPropertiesobject with default values.See
YamlConfigurationStore.update(Path)for an explanation of how the update is done.- Type Parameters:
T- the configuration type- Parameters:
configurationFile- the configuration file that is updatedconfigurationType- the type of configuration- Returns:
- a newly created configuration initialized with values taken from the configuration file
- Throws:
de.exlll.configlib.ConfigurationException- if the configuration cannot be deserializedNullPointerException- if any argument is nullRuntimeException- if loading or saving the configuration throws an exception- See Also:
-
update
public static <T> T update(Path configurationFile, Class<T> configurationType, Consumer<YamlConfigurationProperties.Builder<?>> propertiesConfigurer) Updates a YAML configuration file with a configuration of the given type using aYamlConfigurationPropertiesobject that is built by a builder. The builder is initialized with default values and can be configured by thepropertiesConfigurer.See
YamlConfigurationStore.update(Path)for an explanation of how the update is done.- Type Parameters:
T- the configuration type- Parameters:
configurationFile- the configuration file that is updatedconfigurationType- the type of configurationpropertiesConfigurer- the consumer used to configure the builder- Returns:
- a newly created configuration initialized with values taken from the configuration file
- Throws:
de.exlll.configlib.ConfigurationException- if the configuration cannot be deserializedNullPointerException- if any argument is nullRuntimeException- if loading or saving the configuration throws an exception- See Also:
-
update
public static <T> T update(Path configurationFile, Class<T> configurationType, YamlConfigurationProperties properties) Updates a YAML configuration file with a configuration of the given type using the givenYamlConfigurationPropertiesobject.See
YamlConfigurationStore.update(Path)for an explanation of how the update is done.- Type Parameters:
T- the configuration type- Parameters:
configurationFile- the configuration file that is updatedconfigurationType- the type of configurationproperties- the configuration properties- Returns:
- a newly created configuration initialized with values taken from the configuration file
- Throws:
de.exlll.configlib.ConfigurationException- if the configuration cannot be deserializedNullPointerException- if any argument is nullRuntimeException- if loading or saving the configuration throws an exception- See Also:
-
save
Saves a configuration of the given type to the specified YAML file using aYamlConfigurationPropertiesobject with default values.- Type Parameters:
T- the configuration type- Parameters:
configurationFile- the file the configuration is saved toconfigurationType- the type of configurationconfiguration- the configuration that is saved- Throws:
de.exlll.configlib.ConfigurationException- if the configuration contains invalid values or cannot be serializedNullPointerException- if any argument is nullRuntimeException- if writing the configuration throws an exception- See Also:
-
save
public static <T> void save(Path configurationFile, Class<T> configurationType, T configuration, Consumer<YamlConfigurationProperties.Builder<?>> propertiesConfigurer) Saves a configuration of the given type to the specified YAML file using aYamlConfigurationPropertiesobject that is built by a builder. The builder is initialized with default values and can be configured by thepropertiesConfigurer.- Type Parameters:
T- the configuration type- Parameters:
configurationFile- the file the configuration is saved toconfigurationType- the type of configurationconfiguration- the configuration that is savedpropertiesConfigurer- the consumer used to configure the builder- Throws:
de.exlll.configlib.ConfigurationException- if the configuration contains invalid values or cannot be serializedNullPointerException- if any argument is nullRuntimeException- if writing the configuration throws an exception- See Also:
-
save
public static <T> void save(Path configurationFile, Class<T> configurationType, T configuration, YamlConfigurationProperties properties) Saves a configuration of the given type to the specified YAML file using the givenYamlConfigurationPropertiesobject.- Type Parameters:
T- the configuration type- Parameters:
configurationFile- the file the configuration is saved toconfigurationType- the type of configurationconfiguration- the configuration that is savedproperties- the configuration properties- Throws:
de.exlll.configlib.ConfigurationException- if the configuration contains invalid values or cannot be serializedNullPointerException- if any argument is nullRuntimeException- if writing the configuration throws an exception- See Also:
-
write
public static <T> void write(OutputStream outputStream, Class<T> configurationType, T configuration) Writes a configuration instance to the given output stream using aYamlConfigurationPropertiesobject with default values.- Type Parameters:
T- the configuration type- Parameters:
outputStream- the output stream the configuration is written toconfigurationType- the type of configurationconfiguration- the configuration that is saved- Throws:
de.exlll.configlib.ConfigurationException- if the configuration contains invalid values or cannot be serializedNullPointerException- if any argument is nullRuntimeException- if writing the configuration throws an exception- See Also:
-
write
public static <T> void write(OutputStream outputStream, Class<T> configurationType, T configuration, Consumer<YamlConfigurationProperties.Builder<?>> propertiesConfigurer) Writes a configuration instance to the given output stream using aYamlConfigurationPropertiesobject that is built by a builder. The builder is initialized with default values and can be configured by thepropertiesConfigurer.- Type Parameters:
T- the configuration type- Parameters:
outputStream- the output stream the configuration is written toconfigurationType- the type of configurationconfiguration- the configuration that is savedpropertiesConfigurer- the consumer used to configure the builder- Throws:
de.exlll.configlib.ConfigurationException- if the configuration contains invalid values or cannot be serializedNullPointerException- if any argument is nullRuntimeException- if writing the configuration throws an exception- See Also:
-
write
public static <T> void write(OutputStream outputStream, Class<T> configurationType, T configuration, YamlConfigurationProperties properties) Writes a configuration instance to the given output stream using the givenYamlConfigurationPropertiesobject.- Type Parameters:
T- the configuration type- Parameters:
outputStream- the output stream the configuration is written toconfigurationType- the type of configurationconfiguration- the configuration that is savedproperties- the configuration properties- Throws:
de.exlll.configlib.ConfigurationException- if the configuration contains invalid values or cannot be serializedNullPointerException- if any argument is nullRuntimeException- if writing the configuration throws an exception- See Also:
-