public static class IniEditor.Section extends Object
IniEditor
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).限定符和类型 | 字段和说明 |
---|---|
static String |
DEFAULT_OPTION_FORMAT |
static char |
HEADER_END |
static char |
HEADER_START |
构造器和说明 |
---|
IniEditor.Section(String name)
Constructs a new section.
|
IniEditor.Section(String name,
boolean isCaseSensitive)
Constructs a new section, specifying case-sensitivity.
|
IniEditor.Section(String name,
char[] delims)
Constructs a new section, defining comment delimiters.
|
IniEditor.Section(String name,
char[] delims,
boolean isCaseSensitive)
Constructs a new section, defining comment delimiters.
|
限定符和类型 | 方法和说明 |
---|---|
void |
addBlankLine()
Adds a blank line to the end of this section.
|
void |
addComment(String comment)
Adds a comment line to the end of this section.
|
void |
addComment(String comment,
char delim)
Adds a comment line to the end of this section.
|
String |
get(String option)
Returns an option's value.
|
boolean |
hasOption(String name)
Checks whether a given option exists in this section.
|
void |
load(BufferedReader reader)
Loads options from a reader into this instance.
|
List<String> |
optionNames()
Returns the names of all options in this section.
|
boolean |
remove(String option)
Removes an option if it exists.
|
void |
save(PrintWriter writer)
Prints this section to a print writer.
|
void |
set(String option,
String value)
Sets an option's value and creates the option if it doesn't exist.
|
void |
set(String option,
String value,
char delim)
Sets an option's value and creates the option if it doesn't exist.
|
void |
setOptionFormat(com.aliyun.oss.common.utils.IniEditor.OptionFormat format)
Sets the option format for this section.
|
void |
setOptionFormatString(String formatString)
Sets the option format for this section to the given string.
|
public static final char HEADER_START
public static final char HEADER_END
public IniEditor.Section(String name)
name
- the section's nameIllegalArgumentException
- the section's name is illegalpublic IniEditor.Section(String name, boolean isCaseSensitive)
name
- the section's nameisCaseSensitive
- option names are case-sensitive if this is trueIllegalArgumentException
- the section's name is illegalpublic IniEditor.Section(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 commentsIllegalArgumentException
- the section's name is illegalpublic IniEditor.Section(String name, char[] delims, boolean isCaseSensitive)
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 commentsisCaseSensitive
- option names are case-sensitive if this is trueIllegalArgumentException
- the section's name is illegalpublic void setOptionFormatString(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
timesIllegalArgumentException
- if the format string is illegalpublic void setOptionFormat(com.aliyun.oss.common.utils.IniEditor.OptionFormat format)
format
- a compiled option formatpublic List<String> optionNames()
public boolean hasOption(String name)
name
- the name of the option to test forpublic String get(String option)
option
- the name of the optionnull
if no
option with the specified name existspublic void set(String option, String value)
option
- the option's namevalue
- the option's valueIllegalArgumentException
- the option name is illegal, ie contains a '=' character
or consists only of white spacepublic void set(String option, String value, char delim)
option
- the option's namevalue
- the option's valuedelim
- the delimiter between name and value for this optionIllegalArgumentException
- the option name is illegal, ie contains a '=' character
or consists only of white spacepublic boolean remove(String option)
option
- the name of the optiontrue
if the option was actually removedpublic void addComment(String comment)
comment
- the commentpublic void addComment(String comment, char delim)
comment
- the commentdelim
- the delimiter used to mark the start of this commentpublic void addBlankLine()
public void load(BufferedReader reader) throws IOException
reader
- where to read fromIOException
- at an I/O problempublic void save(PrintWriter writer) throws IOException
writer
- where to writeIOException
- at an I/O problemCopyright © 2019. All Rights Reserved.