java.lang.Object
org.miaixz.bus.setting.Builder
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 Summary
Modifier and TypeMethodDescriptionstatic voidDumps a Java object (e.g., a Map or a bean) to aWriterin YAML format.static voidDumps a Java object to aWriterin YAML format using the specified dumper options.static PropertiesGets aPropertiesobject containing the current system properties.static PropertiesgetProperties(String name) Gets aPropsinstance for a given properties file from the classpath.static PropertiesgetPropertiesFound(String... names) Gets the firstPropsinstance that can be successfully loaded from a list of resource names.static SettinggetSetting(String name) Gets a cachedSettinginstance for a given resource name from the classpath.static SettinggetSettingFirstFound(String... names) Gets the firstSettinginstance that can be successfully loaded from a list of resource names.static <T> TloadYaml(InputStream in, Class<T> type) Loads YAML data from anInputStreamand maps it to the specified class type.static org.miaixz.bus.core.center.map.DictionaryLoads YAML data from aReader, closing the reader upon completion.static <T> TLoads YAML data from aReaderand maps it to the specified class type, closing the reader upon completion.static <T> TLoads YAML data from aReaderand maps it to the specified class type.static org.miaixz.bus.core.center.map.DictionaryLoads a YAML file from the classpath or an absolute path into aDictionary.static <T> TLoads a YAML file from the classpath or an absolute path and maps it to the specified class type.static <T> TParses a YAML string into a nested map structure and flattens it.static <T> TRecursively parses a nested map structure, flattening it into a single map with dot-separated keys.static StringreplaceYamlValue(Properties properties, String value) Replaces placeholders in a string using values from a Properties object.
-
Method Details
-
loadYaml
Loads a YAML file from the classpath or an absolute path into aDictionary.- Parameters:
path- The path to the YAML file.- Returns:
- The loaded content as a
Dictionary.
-
loadYaml
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
Loads YAML data from anInputStreamand 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
Loads YAML data from aReader, closing the reader upon completion.- Parameters:
reader- The reader containing the YAML data.- Returns:
- The loaded content as a
Dictionary.
-
loadYaml
Loads YAML data from aReaderand 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
Loads YAML data from aReaderand 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- Iftrue, the reader will be closed after loading.- Returns:
- The loaded content as an instance of the specified type.
-
parseYaml
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
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
Dumps a Java object (e.g., a Map or a bean) to aWriterin 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 aWriterin 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
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
Gets aPropertiesobject containing the current system properties.- Returns:
- A
Propertiesinstance with system properties.
-
getProperties
Gets aPropsinstance 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
Propsinstance.
-
getPropertiesFound
Gets the firstPropsinstance that can be successfully loaded from a list of resource names.- Parameters:
names- The resource names to try.- Returns:
- The first found
Propsinstance, or null if none are found.
-
getSetting
Gets a cachedSettinginstance 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
Settinginstance.
-
getSettingFirstFound
Gets the firstSettinginstance that can be successfully loaded from a list of resource names.- Parameters:
names- The resource names to try.- Returns:
- The first found
Settinginstance, or null if none are found.
-