Module bus.setting

Class Builder

java.lang.Object
org.miaixz.bus.setting.Builder

public class Builder extends Object
A builder and facade for creating and accessing various configuration file types like IniSetting, Props, and Yaml. This class provides static helper methods that delegate to the specific format handlers.
Since:
Java 17+
Author:
Kimi Liu
  • Method Details

    • loadYaml

      public static org.miaixz.bus.core.center.map.Dictionary loadYaml(String path)
      Loads a YAML file from the classpath or an absolute path into a Dictionary.
      Parameters:
      path - The path to the YAML file.
      Returns:
      The loaded content as a Dictionary.
    • loadYaml

      public static <T> T loadYaml(String path, Class<T> type)
      Loads a YAML file from the classpath or an absolute path and maps it to the specified class type.
      Type Parameters:
      T - The type of the bean to map to.
      Parameters:
      path - The path to the YAML file.
      type - The class type of the target bean.
      Returns:
      The loaded content as an instance of the specified type.
    • loadYaml

      public static <T> T loadYaml(InputStream in, Class<T> type)
      Loads YAML data from an InputStream and maps it to the specified class type.
      Type Parameters:
      T - The type of the bean to map to.
      Parameters:
      in - The input stream containing the YAML data.
      type - The class type of the target bean.
      Returns:
      The loaded content as an instance of the specified type.
    • loadYaml

      public static org.miaixz.bus.core.center.map.Dictionary loadYaml(Reader reader)
      Loads YAML data from a Reader, closing the reader upon completion.
      Parameters:
      reader - The reader containing the YAML data.
      Returns:
      The loaded content as a Dictionary.
    • loadYaml

      public static <T> T loadYaml(Reader reader, Class<T> type)
      Loads YAML data from a Reader and maps it to the specified class type, closing the reader upon completion.
      Type Parameters:
      T - The type of the bean to map to.
      Parameters:
      reader - The reader containing the YAML data.
      type - The class type of the target bean.
      Returns:
      The loaded content as an instance of the specified type.
    • loadYaml

      public static <T> T loadYaml(Reader reader, Class<T> type, boolean isCloseReader)
      Loads YAML data from a Reader and maps it to the specified class type.
      Type Parameters:
      T - The type of the bean to map to.
      Parameters:
      reader - The reader containing the YAML data.
      type - The class type of the target bean.
      isCloseReader - If true, the reader will be closed after loading.
      Returns:
      The loaded content as an instance of the specified type.
    • parseYaml

      public static <T> T parseYaml(String content)
      Parses a YAML string into a nested map structure and flattens it.
      Type Parameters:
      T - The expected return type (typically Map).
      Parameters:
      content - The YAML content as a string.
      Returns:
      A flattened map with dot-separated keys.
    • parseYaml

      public static <T> T parseYaml(String prefix, Map<String,Object> map)
      Recursively parses a nested map structure, flattening it into a single map with dot-separated keys.
      Type Parameters:
      T - The expected return type (typically Map).
      Parameters:
      prefix - The current key prefix for flattening.
      map - The map to parse.
      Returns:
      A flattened map.
    • dumpYaml

      public static void dumpYaml(Object object, Writer writer)
      Dumps a Java object (e.g., a Map or a bean) to a Writer in YAML format.
      Parameters:
      object - The object to dump.
      writer - The writer to which the YAML data will be written.
    • dumpYaml

      public static void dumpYaml(Object object, Writer writer, org.yaml.snakeyaml.DumperOptions dumperOptions)
      Dumps a Java object to a Writer in YAML format using the specified dumper options.
      Parameters:
      object - The object to dump.
      writer - The writer to which the YAML data will be written.
      dumperOptions - The SnakeYAML dumper options to control the output format.
    • replaceYamlValue

      public static String replaceYamlValue(Properties properties, String value)
      Replaces placeholders in a string using values from a Properties object.
      Parameters:
      properties - The properties object containing the replacement values.
      value - The string with placeholders.
      Returns:
      The string with placeholders replaced.
    • getProperties

      public static Properties getProperties()
      Gets a Properties object containing the current system properties.
      Returns:
      A Properties instance with system properties.
    • getProperties

      public static Properties getProperties(String name)
      Gets a Props instance for a given properties file from the classpath.
      Parameters:
      name - The name of the properties file. If no extension is provided, ".properties" is assumed.
      Returns:
      The loaded Props instance.
    • getPropertiesFound

      public static Properties getPropertiesFound(String... names)
      Gets the first Props instance that can be successfully loaded from a list of resource names.
      Parameters:
      names - The resource names to try.
      Returns:
      The first found Props instance, or null if none are found.
    • getSetting

      public static Setting getSetting(String name)
      Gets a cached Setting instance for a given resource name from the classpath.
      Parameters:
      name - The name of the settings file. If no extension is provided, ".setting" is assumed.
      Returns:
      The cached or newly loaded Setting instance.
    • getSettingFirstFound

      public static Setting getSettingFirstFound(String... names)
      Gets the first Setting instance that can be successfully loaded from a list of resource names.
      Parameters:
      names - The resource names to try.
      Returns:
      The first found Setting instance, or null if none are found.