Module bus.setting

Class Loader

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

public class Loader extends Object
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
  • Constructor Details

    • Loader

      public Loader()
      Constructs a new Loader with a default formatter factory.
    • Loader

      public Loader(Factory formatterFactory)
      Constructs a new Loader with a custom formatter factory.
      Parameters:
      formatterFactory - The factory to create the line formatter.
    • Loader

      public Loader(Charset charset, boolean isUseVariable)
      Constructs a new Loader with specified settings.
      Parameters:
      charset - The character set to use.
      isUseVariable - true to 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

      public GroupedMap load(InputStream inputStream) throws IOException
      Loads settings from an InputStream. 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

      public void store(GroupedMap groupedMap, String absolutePath)
      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

      public void store(GroupedMap groupedMap, File file)
      Stores the current settings to a file, overwriting its content.
      Parameters:
      groupedMap - The map of grouped settings to store.
      file - The destination file.
    • setVarRegex

      public Loader setVarRegex(String regex)
      Sets the regular expression for identifying variables (e.g., "\\$\\{(.*?)\\}").
      Parameters:
      regex - The regular expression.
      Returns:
      this Loader instance for chaining.
    • setAssignFlag

      public Loader setAssignFlag(char assignFlag)
      Sets the character used to separate keys from values.
      Parameters:
      assignFlag - The assignment character.
      Returns:
      this Loader instance for chaining.
    • setValueEditor

      public Loader 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. This is called before variable substitution.
      Parameters:
      valueEditor - The value editor function.
      Returns:
      this Loader instance for chaining.
    • getFormatter

      protected Format getFormatter()
      Gets a default formatter using the configured factory and suppliers.
      Returns:
      A new Format instance.
    • read

      public IniSetting read(InputStream in) throws IOException
      Reads INI data from an InputStream.
      Parameters:
      in - an INI data input stream.
      Returns:
      The parsed INI data as an IniSetting.
      Throws:
      IOException - if an I/O error occurs.
    • read

      public IniSetting read(File file) throws IOException
      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

      public IniSetting read(Path path) throws IOException
      Reads an INI file from a Path.
      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

      public IniSetting read(Reader reader) throws IOException
      Reads and parses INI data from a Reader.
      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

      protected IniSetting defaultFormat(Reader reader) throws IOException
      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

      protected IniSetting defaultFormat(Reader reader, int builderCapacity) throws IOException
      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

      public Supplier<ElementFormatter<IniComment>> 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

      public Supplier<ElementFormatter<IniSection>> 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

      public Supplier<ElementFormatter<IniProperty>> 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.