INI Config Format
A config file's on-disk syntax is handled by a ConfigFormat. IniConfigFormat is the INI implementation and the default. The other built-in implementation is YamlConfigFormat (see YAML Config Files).
See the guide: Externalize config with INI/YAML and variables
Selecting the format
If no format is set explicitly, it is auto-detected from the config name:
a name ending in .yaml or .yml (case-insensitive) selects YAML, and anything else selects INI.
So MyConfig.cfg, MyConfig.properties or a name with no extension all use INI.
// INI by name (default).
Config c1 = Config.create("MyConfig.cfg").build();
// Force INI explicitly, e.g. for a file whose name would otherwise look like YAML.
Config c2 = Config.create("MyConfig.yaml").ini().build();
// Equivalent, passing the singleton directly.
Config c3 = Config.create("MyConfig.yaml").format(IniConfigFormat.INSTANCE).build();
The INI syntax
INI is the native syntax of the juneau-config module: [Section] headers, key = value entries, # comments,
imports, and value modifiers.
Because it is the native syntax, the INI format passes the file contents through unchanged when reading,
and when writing it emits the in-memory config directly, preserving the comments and whitespace of the original file.
See the juneau-config overview and Reading Entries.
# A set of entries
[Section1]
# An integer
key1 = 1
# A boolean
key2 = true
The ConfigFormat contract
ConfigFormat is the extension point for alternative file syntaxes.
Every config is held internally as INI-style text; a format translates to and from that representation:
| Method | Purpose |
|---|---|
id() | Format identifier. IniConfigFormat returns "ini"; YamlConfigFormat returns "yaml". |
toInternal(String) | Normalizes source text into the INI-style content used internally. |
fromInternal(ConfigMap) | Serializes the config back to this format. |
For IniConfigFormat, toInternal returns the input unchanged (an empty string for null), and fromInternal writes the INI text of the config.
The singleton is available as IniConfigFormat.INSTANCE.