public class Ini extends Object implements Map<String,Ini.Section>
Section
s, keyed by section name. Each
Section
is itself a map of String
name/value pairs. Name/value pairs are guaranteed to be unique
within each Section
only - not across the entire Ini
instance.Modifier and Type | Class and Description |
---|---|
static class |
Ini.Section
|
Modifier and Type | Field and Description |
---|---|
static String |
COMMENT_POUND |
static String |
COMMENT_SEMICOLON |
static String |
DEFAULT_CHARSET_NAME |
static String |
DEFAULT_SECTION_NAME |
protected static char |
ESCAPE_TOKEN |
static String |
SECTION_PREFIX |
static String |
SECTION_SUFFIX |
Constructor and Description |
---|
Ini()
Creates a new empty
Ini instance. |
Ini(Ini defaults)
Creates a new
Ini instance with the specified defaults. |
Modifier and Type | Method and Description |
---|---|
Ini.Section |
addSection(String sectionName)
Ensures a section with the specified name exists, adding a new one if it does not yet exist.
|
void |
clear() |
boolean |
containsKey(Object key) |
boolean |
containsValue(Object value) |
Set<Map.Entry<String,Ini.Section>> |
entrySet() |
boolean |
equals(Object obj) |
static Ini |
fromResourcePath(String resourcePath)
Creates a new
Ini instance loaded with the INI-formatted data in the resource at the given path. |
Ini.Section |
get(Object key) |
Ini.Section |
getSection(String sectionName)
Returns the
Ini.Section with the given name or null if no section with that name exists. |
protected static String |
getSectionName(String line) |
Set<String> |
getSectionNames()
Returns the names of all sections managed by this
Ini instance or an empty collection if there are
no sections. |
String |
getSectionProperty(String sectionName,
String propertyName)
Returns the value of the specified section property, or
null if the section or property do not exist. |
String |
getSectionProperty(String sectionName,
String propertyName,
String defaultValue)
Returns the value of the specified section property, or the
defaultValue if the section or
property do not exist. |
Collection<Ini.Section> |
getSections()
Returns the sections managed by this
Ini instance or an empty collection if there are
no sections. |
int |
hashCode() |
boolean |
isEmpty()
Returns
true if no sections have been configured, or if there are sections, but the sections themselves
are all empty, false otherwise. |
protected static boolean |
isSectionHeader(String line) |
Set<String> |
keySet() |
void |
load(InputStream is)
Loads the INI-formatted text backed by the given InputStream into this instance.
|
void |
load(Reader reader)
Loads the INI-formatted text backed by the given Reader into this instance.
|
void |
load(Scanner scanner)
Loads the INI-formatted text backed by the given Scanner.
|
void |
load(String iniConfig)
Loads the specified raw INI-formatted text into this instance.
|
void |
loadFromPath(String resourcePath)
Loads data from the specified resource path into this current
Ini instance. |
void |
merge(Map<String,Ini.Section> m)
Merges the contents of
m 's Ini.Section objects into self. |
Ini.Section |
put(String key,
Ini.Section value) |
void |
putAll(Map<? extends String,? extends Ini.Section> m) |
Ini.Section |
remove(Object key) |
Ini.Section |
removeSection(String sectionName)
Removes the section with the specified name and returns it, or
null if the section did not exist. |
void |
setSectionProperty(String sectionName,
String propertyName,
String propertyValue)
Sets a name/value pair for the section with the given
sectionName . |
int |
size() |
String |
toString() |
Collection<Ini.Section> |
values() |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
public static final String DEFAULT_SECTION_NAME
public static final String DEFAULT_CHARSET_NAME
public static final String COMMENT_POUND
public static final String COMMENT_SEMICOLON
public static final String SECTION_PREFIX
public static final String SECTION_SUFFIX
protected static final char ESCAPE_TOKEN
public Ini()
Ini
instance.public boolean isEmpty()
true
if no sections have been configured, or if there are sections, but the sections themselves
are all empty, false
otherwise.isEmpty
in interface Map<String,Ini.Section>
true
if no sections have been configured, or if there are sections, but the sections themselves
are all empty, false
otherwise.public Set<String> getSectionNames()
Ini
instance or an empty collection if there are
no sections.Ini
instance or an empty collection if there are
no sections.public Collection<Ini.Section> getSections()
Ini
instance or an empty collection if there are
no sections.Ini
instance or an empty collection if there are
no sections.public Ini.Section getSection(String sectionName)
Ini.Section
with the given name or null
if no section with that name exists.sectionName
- the name of the section to retrieve.Ini.Section
with the given name or null
if no section with that name exists.public Ini.Section addSection(String sectionName)
sectionName
- the name of the section to ensure existencepublic Ini.Section removeSection(String sectionName)
null
if the section did not exist.sectionName
- the name of the section to remove.null
if the section did not exist.public void setSectionProperty(String sectionName, String propertyName, String propertyValue)
sectionName
. If the section does not yet exist,
it will be created. If the sectionName
is null or empty, the name/value pair will be placed in the
default (unnamed, empty string) section.sectionName
- the name of the section to add the name/value pairpropertyName
- the name of the property to addpropertyValue
- the property valuepublic String getSectionProperty(String sectionName, String propertyName)
null
if the section or property do not exist.sectionName
- the name of the section to retrieve to acquire the property valuepropertyName
- the name of the section property for which to return the valuenull
if the section or property do not exist.public String getSectionProperty(String sectionName, String propertyName, String defaultValue)
defaultValue
if the section or
property do not exist.sectionName
- the name of the section to add the name/value pairpropertyName
- the name of the property to adddefaultValue
- the default value to return if the section or property do not exist.defaultValue
if the section or
property do not exist.public static Ini fromResourcePath(String resourcePath) throws ConfigurationException
Ini
instance loaded with the INI-formatted data in the resource at the given path. The
resource path may be any value interpretable by the
ResourceUtils.getInputStreamForPath
method.resourcePath
- the resource location of the INI data to load when creating the Ini
instance.Ini
instance loaded with the INI-formatted data in the resource at the given path.ConfigurationException
- if the path cannot be loaded into an Ini
instance.public void loadFromPath(String resourcePath) throws ConfigurationException
Ini
instance. The
resource path may be any value interpretable by the
ResourceUtils.getInputStreamForPath
method.resourcePath
- the resource location of the INI data to load into this instance.ConfigurationException
- if the path cannot be loadedpublic void load(String iniConfig) throws ConfigurationException
iniConfig
- the raw INI-formatted text to load into this instance.ConfigurationException
- if the text cannot be loadedpublic void load(InputStream is) throws ConfigurationException
is
- the InputStream
from which to read the INI-formatted textConfigurationException
- if unablepublic void load(Reader reader)
reader
- the Reader
from which to read the INI-formatted textpublic void merge(Map<String,Ini.Section> m)
m
's Ini.Section
objects into self.
This differs from putAll(Map)
, in that each section is merged with the existing one.
For example the following two ini blocks are merged and the result is the thirdInitial:
[section1]
key1 = value1
[section2]
key2 = value2
To be merged:
[section1]
foo = bar
[section2]
key2 = new value
Result:
[section1]
key1 = value1
foo = bar
[section2]
key2 = new value
m
- map to be mergedpublic void load(Scanner scanner)
scanner
- the Scanner
from which to read the INI-formatted textprotected static boolean isSectionHeader(String line)
protected static String getSectionName(String line)
public int hashCode()
public int size()
size
in interface Map<String,Ini.Section>
public boolean containsKey(Object key)
containsKey
in interface Map<String,Ini.Section>
public boolean containsValue(Object value)
containsValue
in interface Map<String,Ini.Section>
public Ini.Section get(Object key)
get
in interface Map<String,Ini.Section>
public Ini.Section put(String key, Ini.Section value)
put
in interface Map<String,Ini.Section>
public Ini.Section remove(Object key)
remove
in interface Map<String,Ini.Section>
public void putAll(Map<? extends String,? extends Ini.Section> m)
putAll
in interface Map<String,Ini.Section>
public void clear()
clear
in interface Map<String,Ini.Section>
public Collection<Ini.Section> values()
values
in interface Map<String,Ini.Section>
public Set<Map.Entry<String,Ini.Section>> entrySet()
entrySet
in interface Map<String,Ini.Section>
Copyright © 2004–2023 The Apache Software Foundation. All rights reserved.