|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.crosswire.common.util.IniSection
public final class IniSection
A utility class for a section of an INI style configuration file. Keys and values are maintained in insertion order. A key may have more than one value.
SWORD defines a conf as an INI file with one or more sections. Originally, all modules were described in a single conf, but now each module has its own conf.
SWORD will be using a single conf to hold overrides for many
modules. This is the motivation for this class as opposed to
allowing only a single section as IniSection
.
Since the most common use case is for a single section, this implementation has an API for delegating to the first IniSection.
This implementation allows for:
The GNU Lesser General Public License for details.
The copyright to this program is held by its authors.
Field Summary | |
---|---|
private String |
charset
|
private File |
configFile
|
private List<String> |
list
Indexed list of sections maintaining insertion order. |
private static int |
MAX_BUFF_SIZE
Buffer size is based on file size but keep it with within reasonable limits |
private String |
name
The name of the section. |
private Map<String,ListSet<String>> |
section
A map of sections by section names. |
private StringBuilder |
warnings
|
Constructor Summary | |
---|---|
IniSection()
Create an empty INI config without a name. |
|
IniSection(IniSection config)
Copy constructor |
|
IniSection(String name)
Create an empty INI Config. |
Method Summary | |
---|---|
boolean |
add(String key,
String value)
Add a value for the key. |
private String |
advance(BufferedReader bin)
Get the next line from the input |
private boolean |
allowed(String key,
String value)
|
void |
clear()
Start over. |
boolean |
containsKey(String key)
Returns true if the IniSection contains any values for the specified key. |
boolean |
containsValue(String value)
Returns true if the IniSection contains the specified value for any key. |
boolean |
containsValue(String key,
String value)
Returns true if the IniSection contains the specified value for the given key. |
private String |
format(String value)
A helper to format the output of the content as expected |
String |
get(String key)
Get the first value for the key. |
String |
get(String key,
int index)
Get the value for the key specified by the index. |
String |
get(String key,
String defaultValue)
|
List<String> |
getKeys()
Get the unmodifiable ordered list of keys. |
String |
getName()
Get the [name] of this section |
private Collection<String> |
getOrCreateValues(String key)
|
private int |
getSplitPos(String line)
Does this line of text represent a key/value pair? |
Collection<String> |
getValues(String key)
Get the unmodifiable collection of values of a key. |
private boolean |
isCommentLine(String line)
Determine if the given line is a blank or a comment line. |
boolean |
isEmpty()
Determine whether this section has any keys |
private boolean |
isSectionLine(String line)
Is this line a [section]? |
Iterator |
iterator()
|
void |
load(byte[] buffer,
String encoding)
Load the conf from a buffer. |
void |
load(File file,
String encoding)
Load the INI from a file using the given encoding. |
void |
load(InputStream is,
String encoding)
|
private void |
load(Reader in)
|
private String |
more(BufferedReader bin,
String value)
Get continuation lines, if any. |
private static boolean |
more(String line)
Is there more following this line |
boolean |
remove(String key)
Remove the value if present. |
boolean |
remove(String key,
String value)
Remove the value if present. |
boolean |
replace(String key,
String value)
Replace the value(s) for the key with a new value. |
String |
report()
Obtain a report of issues with this IniSection. |
void |
save()
Save this INI to the file from which it was loaded. |
void |
save(File file,
String encoding)
Save the INI to a file using the given encoding. |
void |
save(Writer out)
Output this section using the print writer. |
void |
setName(String name)
Set the name of this INI config. |
int |
size()
Get the number of keys in this section. |
int |
size(String key)
Get the number of values for a key. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private String name
private Map<String,ListSet<String>> section
private List<String> list
private File configFile
private String charset
private StringBuilder warnings
private static final int MAX_BUFF_SIZE
Constructor Detail |
---|
public IniSection()
public IniSection(String name)
name
- the section namepublic IniSection(IniSection config)
config
- the config to copyMethod Detail |
---|
public void clear()
public void setName(String name)
name
- public String getName()
public int size()
public boolean isEmpty()
true
if this section is emptypublic Iterator iterator()
iterator
in interface Iterable
public List<String> getKeys()
public boolean containsKey(String key)
true
if the IniSection contains any values for the specified key.
key
- key to search for in IniSection
true
if the key existspublic boolean containsValue(String value)
true
if the IniSection contains the specified value for any key.
value
- value to search for in IniSection
true
if the value exists.public boolean containsValue(String key, String value)
true
if the IniSection contains the specified value for the given key.
key
- the key for the sectionvalue
- value to search for in IniSection
true
if the value exists.public boolean add(String key, String value)
key
- the key for the sectionvalue
- the value for the key
public Collection<String> getValues(String key)
key
- the key
public int size(String key)
key
- the key
public String get(String key, int index)
key
- the keyindex
- the index
ArrayIndexOutOfBoundsException
- when the index is out of boundspublic String get(String key)
key
- the key
public String get(String key, String defaultValue)
public boolean remove(String key, String value)
key
- the key for the sectionvalue
- the value for the key
public boolean remove(String key)
key
- the key for the section
public boolean replace(String key, String value)
key
- the key for the sectionvalue
- the value for the key
public void load(InputStream is, String encoding) throws IOException
IOException
public void load(File file, String encoding) throws IOException
file
- the file to loadencoding
- the encoding of the file
IOException
public void load(byte[] buffer, String encoding) throws IOException
buffer
- the buffer to loadencoding
- the character encoding of this INI
IOException
public void save() throws IOException
IOException
public void save(File file, String encoding) throws IOException
file
- the file to loadencoding
- the encoding of the file
IOException
public void save(Writer out)
out
- the output streampublic String report()
private String format(String value)
value
- the value to be formatted
private Collection<String> getOrCreateValues(String key)
private void load(Reader in) throws IOException
IOException
private String advance(BufferedReader bin) throws IOException
bin
- The reader to get data from
IOException
- if encounteredprivate boolean isCommentLine(String line)
line
- The line to check.
private boolean isSectionLine(String line)
line
- The line to check.
private int getSplitPos(String line)
line
- The line to check.
private String more(BufferedReader bin, String value) throws IOException
IOException
private static boolean more(String line)
line
- the trimmed string to check
private boolean allowed(String key, String value)
|
Copyright ยจ 2003-2015 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |