public static class IniFileManager.Section
extends java.lang.Object
IniFileManager and
should rarely ever be used directly. It's exposed because it can be useful
for plain, section-less configuration files (Java-style properties, for
example).| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
DEFAULT_OPTION_FORMAT |
static char |
HEADER_END |
static char |
HEADER_START |
| Constructor and Description |
|---|
Section(java.lang.String name)
Constructs a new section.
|
Section(java.lang.String name,
char[] delims)
Constructs a new section, defining comment delimiters.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addBlankLine()
Adds a blank line to the end of this section.
|
void |
addComment(java.lang.String comment)
Adds a comment line to the end of this section.
|
void |
addComment(java.lang.String comment,
char delim)
Adds a comment line to the end of this section.
|
void |
clear()
Clears all options from this section.
|
java.lang.String |
get(java.lang.String option)
Returns an option's value.
|
boolean |
hasOption(java.lang.String name)
Checks whether a given option exists in this section.
|
void |
load(java.io.BufferedReader reader)
Loads options from a reader into this instance.
|
java.util.List<java.lang.String> |
optionNames()
Returns the names of all options in this section.
|
boolean |
remove(java.lang.String option)
Removes an option if it exists.
|
void |
save(java.io.PrintWriter writer)
Prints this section to a print writer.
|
void |
set(java.lang.String option,
java.lang.String value)
Sets an option's value and creates the option if it doesn't exist.
|
void |
set(java.lang.String option,
java.lang.String value,
char delim)
Sets an option's value and creates the option if it doesn't exist.
|
void |
setOptionFormat(jgamebase.tools.IniFileManager.OptionFormat format)
Sets the option format for this section.
|
void |
setOptionFormatString(java.lang.String formatString)
Sets the option format for this section to the given string.
|
public static final java.lang.String DEFAULT_OPTION_FORMAT
public static final char HEADER_START
public static final char HEADER_END
public Section(java.lang.String name)
name - the section's namejava.lang.IllegalArgumentException - the section's name is illegalpublic Section(java.lang.String name,
char[] delims)
name - the section's namedelims - an array of characters to be recognized as starters of comment
lines; the first of them will be used for newly created commentsjava.lang.IllegalArgumentException - the section's name is illegalpublic void clear()
public void setOptionFormatString(java.lang.String formatString)
%s three times, these will be replaced with the
option name, the option separator and the option value in this order. Literal
percentage signs must be escaped by preceding them with another percentage
sign (i.e., %% corresponds to one percentage sign). The default
format string is "%s %s %s".
Option formats may look like format strings as supported by Java 1.5, but the
string is in fact parsed in a custom fashion to guarantee backwards
compatibility. So don't try clever stuff like using format conversion types
other than %s.formatString - a format string, containing %s exactly three timesjava.lang.IllegalArgumentException - if the format string is illegalpublic void setOptionFormat(jgamebase.tools.IniFileManager.OptionFormat format)
format - a compiled option formatpublic java.util.List<java.lang.String> optionNames()
public boolean hasOption(java.lang.String name)
name - the name of the option to test forpublic java.lang.String get(java.lang.String option)
option - the name of the optionnull if no option with
the specified name existspublic void set(java.lang.String option,
java.lang.String value)
option - the option's namevalue - the option's valuejava.lang.IllegalArgumentException - the option name is illegal, ie contains a '=' character or
consists only of white spacepublic void set(java.lang.String option,
java.lang.String value,
char delim)
option - the option's namevalue - the option's valuedelim - the delimiter between name and value for this optionjava.lang.IllegalArgumentException - the option name is illegal, ie contains a '=' character or
consists only of white spacepublic boolean remove(java.lang.String option)
option - the name of the optiontrue if the option was actually removedpublic void addComment(java.lang.String comment)
comment - the commentpublic void addComment(java.lang.String comment,
char delim)
comment - the commentdelim - the delimiter used to mark the start of this commentpublic void addBlankLine()
public void load(java.io.BufferedReader reader)
throws java.io.IOException
reader - where to read fromjava.io.IOException - at an I/O problempublic void save(java.io.PrintWriter writer)
throws java.io.IOException
writer - where to writejava.io.IOException - at an I/O problem