Class YamlConfigurations

java.lang.Object
de.exlll.configlib.YamlConfigurations

public final class YamlConfigurations extends Object
This class contains convenience methods for reading, writing, loading, saving, and updating configurations.
  • Method Summary

    Modifier and Type
    Method
    Description
    static <T> T
    load(Path configurationFile, Class<T> configurationType)
    Loads a configuration of the given type from the specified YAML file using a YamlConfigurationProperties object with default values.
    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 given YamlConfigurationProperties object.
    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 a YamlConfigurationProperties object that is built by a builder.
    static <T> T
    read(InputStream inputStream, Class<T> configurationType)
    Reads a configuration of the given type from the given input stream using a YamlConfigurationProperties object with default values.
    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 given YamlConfigurationProperties object.
    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 a YamlConfigurationProperties object that is built by a builder.
    static <T> void
    save(Path configurationFile, Class<T> configurationType, T configuration)
    Saves a configuration of the given type to the specified YAML file using a YamlConfigurationProperties object with default values.
    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 given YamlConfigurationProperties object.
    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 a YamlConfigurationProperties object that is built by a builder.
    static <T> T
    update(Path configurationFile, Class<T> configurationType)
    Updates a YAML configuration file with a configuration of the given type using a YamlConfigurationProperties object with default values.
    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 given YamlConfigurationProperties object.
    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 a YamlConfigurationProperties object that is built by a builder.
    static <T> void
    write(OutputStream outputStream, Class<T> configurationType, T configuration)
    Writes a configuration instance to the given output stream using a YamlConfigurationProperties object with default values.
    static <T> void
    write(OutputStream outputStream, Class<T> configurationType, T configuration, YamlConfigurationProperties properties)
    Writes a configuration instance to the given output stream using the given YamlConfigurationProperties object.
    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 a YamlConfigurationProperties object that is built by a builder.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • load

      public static <T> T load(Path configurationFile, Class<T> configurationType)
      Loads a configuration of the given type from the specified YAML file using a YamlConfigurationProperties object with default values.
      Type Parameters:
      T - the configuration type
      Parameters:
      configurationFile - the file the configuration is loaded from
      configurationType - 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 deserialized
      IllegalArgumentException - if the file does not exist or is not a regular file
      NullPointerException - if any parameter is null
      RuntimeException - 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 a YamlConfigurationProperties object that is built by a builder. The builder is initialized with default values and can be configured by the propertiesConfigurer.
      Type Parameters:
      T - the configuration type
      Parameters:
      configurationFile - the file the configuration is loaded from
      configurationType - the type of configuration
      propertiesConfigurer - 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 deserialized
      IllegalArgumentException - if the file does not exist or is not a regular file
      NullPointerException - if any parameter is null
      RuntimeException - 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 given YamlConfigurationProperties object.
      Type Parameters:
      T - the configuration type
      Parameters:
      configurationFile - the file the configuration is loaded from
      configurationType - the type of configuration
      properties - 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 deserialized
      IllegalArgumentException - if the file does not exist or is not a regular file
      NullPointerException - if any parameter is null
      RuntimeException - if reading the configuration throws an exception
      See Also:
    • read

      public static <T> T read(InputStream inputStream, Class<T> configurationType)
      Reads a configuration of the given type from the given input stream using a YamlConfigurationProperties object with default values.
      Type Parameters:
      T - the configuration type
      Parameters:
      inputStream - the input stream the configuration is read from
      configurationType - 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 deserialized
      NullPointerException - if any parameter is null
      RuntimeException - 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 a YamlConfigurationProperties object that is built by a builder. The builder is initialized with default values and can be configured by the propertiesConfigurer.
      Type Parameters:
      T - the configuration type
      Parameters:
      inputStream - the input stream the configuration is read from
      configurationType - the type of configuration
      propertiesConfigurer - 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 deserialized
      NullPointerException - if any parameter is null
      RuntimeException - 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 given YamlConfigurationProperties object.
      Type Parameters:
      T - the configuration type
      Parameters:
      inputStream - the input stream the configuration is read from
      configurationType - the type of configuration
      properties - the configuration properties
      Returns:
      a newly created configuration initialized with values read from inputStream
      Throws:
      de.exlll.configlib.ConfigurationException - if the configuration cannot be deserialized
      NullPointerException - if any parameter is null
      RuntimeException - if reading the configuration throws an exception
      See Also:
    • update

      public static <T> T update(Path configurationFile, Class<T> configurationType)
      Updates a YAML configuration file with a configuration of the given type using a YamlConfigurationProperties object 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 updated
      configurationType - 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 deserialized
      NullPointerException - if any argument is null
      RuntimeException - 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 a YamlConfigurationProperties object that is built by a builder. The builder is initialized with default values and can be configured by the propertiesConfigurer.

      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 updated
      configurationType - the type of configuration
      propertiesConfigurer - 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 deserialized
      NullPointerException - if any argument is null
      RuntimeException - 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 given YamlConfigurationProperties object.

      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 updated
      configurationType - the type of configuration
      properties - 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 deserialized
      NullPointerException - if any argument is null
      RuntimeException - if loading or saving the configuration throws an exception
      See Also:
    • save

      public static <T> void save(Path configurationFile, Class<T> configurationType, T configuration)
      Saves a configuration of the given type to the specified YAML file using a YamlConfigurationProperties object with default values.
      Type Parameters:
      T - the configuration type
      Parameters:
      configuration - the configuration that is saved
      configurationType - the type of configuration
      configurationFile - the file the configuration is saved to
      Throws:
      de.exlll.configlib.ConfigurationException - if the configuration contains invalid values or cannot be serialized
      NullPointerException - if any argument is null
      RuntimeException - 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 a YamlConfigurationProperties object that is built by a builder. The builder is initialized with default values and can be configured by the propertiesConfigurer.
      Type Parameters:
      T - the configuration type
      Parameters:
      configuration - the configuration that is saved
      configurationType - the type of configuration
      configurationFile - the file the configuration is saved to
      propertiesConfigurer - the consumer used to configure the builder
      Throws:
      de.exlll.configlib.ConfigurationException - if the configuration contains invalid values or cannot be serialized
      NullPointerException - if any argument is null
      RuntimeException - 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 given YamlConfigurationProperties object.
      Type Parameters:
      T - the configuration type
      Parameters:
      configuration - the configuration that is saved
      configurationType - the type of configuration
      configurationFile - the file the configuration is saved to
      properties - the configuration properties
      Throws:
      de.exlll.configlib.ConfigurationException - if the configuration contains invalid values or cannot be serialized
      NullPointerException - if any argument is null
      RuntimeException - 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 a YamlConfigurationProperties object with default values.
      Type Parameters:
      T - the configuration type
      Parameters:
      configuration - the configuration that is saved
      configurationType - the type of configuration
      outputStream - the output stream the configuration is written to
      Throws:
      de.exlll.configlib.ConfigurationException - if the configuration contains invalid values or cannot be serialized
      NullPointerException - if any argument is null
      RuntimeException - 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 a YamlConfigurationProperties object that is built by a builder. The builder is initialized with default values and can be configured by the propertiesConfigurer.
      Type Parameters:
      T - the configuration type
      Parameters:
      configuration - the configuration that is saved
      configurationType - the type of configuration
      outputStream - the output stream the configuration is written to
      propertiesConfigurer - the consumer used to configure the builder
      Throws:
      de.exlll.configlib.ConfigurationException - if the configuration contains invalid values or cannot be serialized
      NullPointerException - if any argument is null
      RuntimeException - 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 given YamlConfigurationProperties object.
      Type Parameters:
      T - the configuration type
      Parameters:
      configuration - the configuration that is saved
      configurationType - the type of configuration
      outputStream - the output stream the configuration is written to
      properties - the configuration properties
      Throws:
      de.exlll.configlib.ConfigurationException - if the configuration contains invalid values or cannot be serialized
      NullPointerException - if any argument is null
      RuntimeException - if writing the configuration throws an exception
      See Also: