Module bus.setting

Class DefaultFormatter

java.lang.Object
org.miaixz.bus.setting.format.DefaultFormatter
All Implemented Interfaces:
Closeable, AutoCloseable, Format

public class DefaultFormatter extends Object implements Format
The default line formatter for INI files. It uses a chain of responsibility pattern, attempting to parse a line as a comment, a section, or a property, in that order.
Since:
Java 17+
Author:
Kimi Liu
  • Field Details

    • commentElementFormatter

      protected final ElementFormatter<IniComment> commentElementFormatter
      Formatter for comment lines.
    • sectionElementFormatter

      protected final ElementFormatter<IniSection> sectionElementFormatter
      Formatter for section headers.
    • propertyElementFormatter

      protected final ElementFormatter<IniProperty> propertyElementFormatter
      Formatter for property lines (key-value pairs).
    • lastSection

      protected IniSection lastSection
      The most recently parsed section, used to associate properties with it.
  • Constructor Details

    • DefaultFormatter

      public DefaultFormatter(ElementFormatter<IniComment> commentElementFormatter, ElementFormatter<IniSection> sectionElementFormatter, ElementFormatter<IniProperty> propertyElementFormatter)
      Constructs a new DefaultFormatter with the specified element formatters.
      Parameters:
      commentElementFormatter - The formatter for comments.
      sectionElementFormatter - The formatter for sections.
      propertyElementFormatter - The formatter for properties.
  • Method Details

    • formatLine

      public IniElement formatLine(String raw)
      Formats a raw line from an INI file into an IniElement. Empty lines are ignored and return null.
      Specified by:
      formatLine in interface Format
      Parameters:
      raw - The raw string data for the line.
      Returns:
      The parsed IniElement, or null for an empty line.
      Throws:
      org.miaixz.bus.core.lang.exception.InternalException - if the line cannot be parsed as a comment, section, or property.
    • init

      public void init()
      Resets the formatter to its initial state, clearing the line counters and the last seen section. This should be called before parsing a new file.
      Specified by:
      init in interface Format