java.lang.Object
org.miaixz.bus.setting.Loader
A loader for
.setting files. This class handles the parsing of INI-style configuration files, including
support for sections (groups), variable substitution, and custom line formatters.- Since:
- Java 17+
- Author:
- Kimi Liu
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceA functional interface for editing a property value during the loading process. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected IniSettingdefaultFormat(Reader reader) Parses the content from a reader line by line using the default format.protected IniSettingdefaultFormat(Reader reader, int builderCapacity) Parses the content from a reader line by line.protected FormatGets a default formatter using the configured factory and suppliers.load(InputStream inputStream) Loads settings from anInputStream.load(org.miaixz.bus.core.io.resource.Resource resource) Loads a settings file from the given resource.Reads an INI file.read(InputStream in) Reads INI data from anInputStream.Reads and parses INI data from aReader.Reads an INI file from aPath.setAssignFlag(char assignFlag) Sets the character used to separate keys from values.voidsetCommentElementFormatterSupplier(Supplier<ElementFormatter<IniComment>> commentElementFormatterSupplier) Sets the supplier for the comment formatter.voidsetPropertyElementFormatterSupplier(Supplier<ElementFormatter<IniProperty>> propertyElementFormatterSupplier) Sets the supplier for the property formatter.voidsetSectionElementFormatterSupplier(Supplier<ElementFormatter<IniSection>> sectionElementFormatterSupplier) Sets the supplier for the section formatter.setValueEditor(Loader.ValueEditor valueEditor) Sets a custom value editor, which can be used to modify values (e.g., for decryption) as they are being loaded.setVarRegex(String regex) Sets the regular expression for identifying variables (e.g.,"\\$\\{(.*?)\\}").voidstore(GroupedMap groupedMap, File file) Stores the current settings to a file, overwriting its content.voidstore(GroupedMap groupedMap, String absolutePath) Stores the current settings to a file at the specified absolute path, overwriting its content.
-
Constructor Details
-
Loader
public Loader()Constructs a new Loader with a default formatter factory. -
Loader
Constructs a new Loader with a custom formatter factory.- Parameters:
formatterFactory- The factory to create the line formatter.
-
Loader
Constructs a new Loader with specified settings.- Parameters:
charset- The character set to use.isUseVariable-trueto enable variable substitution.
-
-
Method Details
-
load
public GroupedMap load(org.miaixz.bus.core.io.resource.Resource resource) throws org.miaixz.bus.core.lang.exception.NotFoundException Loads a settings file from the given resource.- Parameters:
resource- The resource representing the configuration file.- Returns:
- The loaded settings as a
GroupedMap. - Throws:
org.miaixz.bus.core.lang.exception.NotFoundException- if the resource cannot be found or read.
-
load
Loads settings from anInputStream. This method does not close the stream.- Parameters:
inputStream- The input stream to read from.- Returns:
- The loaded settings as a
GroupedMap. - Throws:
IOException- if an I/O error occurs.
-
store
Stores the current settings to a file at the specified absolute path, overwriting its content.- Parameters:
groupedMap- The map of grouped settings to store.absolutePath- The absolute path to the destination file.
-
store
Stores the current settings to a file, overwriting its content.- Parameters:
groupedMap- The map of grouped settings to store.file- The destination file.
-
setVarRegex
Sets the regular expression for identifying variables (e.g.,"\\$\\{(.*?)\\}").- Parameters:
regex- The regular expression.- Returns:
- this
Loaderinstance for chaining.
-
setAssignFlag
Sets the character used to separate keys from values.- Parameters:
assignFlag- The assignment character.- Returns:
- this
Loaderinstance for chaining.
-
setValueEditor
Sets a custom value editor, which can be used to modify values (e.g., for decryption) as they are being loaded. This is called before variable substitution.- Parameters:
valueEditor- The value editor function.- Returns:
- this
Loaderinstance for chaining.
-
getFormatter
Gets a default formatter using the configured factory and suppliers.- Returns:
- A new
Formatinstance.
-
read
Reads INI data from anInputStream.- Parameters:
in- an INI data input stream.- Returns:
- The parsed INI data as an
IniSetting. - Throws:
IOException- if an I/O error occurs.
-
read
Reads an INI file.- Parameters:
file- The INI file.- Returns:
- The parsed INI data as an
IniSetting. - Throws:
IOException- if an I/O error occurs.
-
read
Reads an INI file from aPath.- Parameters:
path- The path to the INI file.- Returns:
- The parsed INI data as an
IniSetting. - Throws:
IOException- if an I/O error occurs.
-
read
Reads and parses INI data from aReader.- Parameters:
reader- The reader containing the INI data.- Returns:
- The parsed INI data as an
IniSetting. - Throws:
IOException- if an I/O error occurs.
-
defaultFormat
Parses the content from a reader line by line using the default format.- Parameters:
reader- The reader to parse.- Returns:
- The parsed INI data as an
IniSetting. - Throws:
IOException- if an I/O error occurs.
-
defaultFormat
Parses the content from a reader line by line.- Parameters:
reader- The reader to parse.builderCapacity- The initial capacity for the line buffer.- Returns:
- The parsed INI data as an
IniSetting. - Throws:
IOException- if an I/O error occurs.
-
getCommentElementFormatterSupplier
- Returns:
- The supplier for the comment formatter.
-
setCommentElementFormatterSupplier
public void setCommentElementFormatterSupplier(Supplier<ElementFormatter<IniComment>> commentElementFormatterSupplier) Sets the supplier for the comment formatter.- Parameters:
commentElementFormatterSupplier- The new supplier.
-
getSectionElementFormatterSupplier
- Returns:
- The supplier for the section formatter.
-
setSectionElementFormatterSupplier
public void setSectionElementFormatterSupplier(Supplier<ElementFormatter<IniSection>> sectionElementFormatterSupplier) Sets the supplier for the section formatter.- Parameters:
sectionElementFormatterSupplier- The new supplier.
-
getPropertyElementFormatterSupplier
- Returns:
- The supplier for the property formatter.
-
setPropertyElementFormatterSupplier
public void setPropertyElementFormatterSupplier(Supplier<ElementFormatter<IniProperty>> propertyElementFormatterSupplier) Sets the supplier for the property formatter.- Parameters:
propertyElementFormatterSupplier- The new supplier.
-