java.lang.Object
org.miaixz.bus.setting.format.DefaultFormatter
- All Implemented Interfaces:
Closeable,AutoCloseable,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 Summary
FieldsModifier and TypeFieldDescriptionprotected final ElementFormatter<IniComment> Formatter for comment lines.protected IniSectionThe most recently parsed section, used to associate properties with it.protected final ElementFormatter<IniProperty> Formatter for property lines (key-value pairs).protected final ElementFormatter<IniSection> Formatter for section headers. -
Constructor Summary
ConstructorsConstructorDescriptionDefaultFormatter(ElementFormatter<IniComment> commentElementFormatter, ElementFormatter<IniSection> sectionElementFormatter, ElementFormatter<IniProperty> propertyElementFormatter) Constructs a new DefaultFormatter with the specified element formatters. -
Method Summary
Modifier and TypeMethodDescriptionformatLine(String raw) Formats a raw line from an INI file into anIniElement.voidinit()Resets the formatter to its initial state, clearing the line counters and the last seen section.
-
Field Details
-
commentElementFormatter
Formatter for comment lines. -
sectionElementFormatter
Formatter for section headers. -
propertyElementFormatter
Formatter for property lines (key-value pairs). -
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
Formats a raw line from an INI file into anIniElement. Empty lines are ignored and return null.- Specified by:
formatLinein interfaceFormat- 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.
-