|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.crosswire.common.util.Ini
final class Ini
A utility class for loading an INI style, Multimap configuration file.
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 List<String> |
list
Indexed list of sections maintaining insertion order. |
private static org.slf4j.Logger |
LOGGER
The log stream |
private static int |
MAX_BUFF_SIZE
Buffer size is based on file size but keep it with within reasonable limits |
private Map<String,IniSection> |
sectionMap
A map of sections by section names. |
Constructor Summary | |
---|---|
Ini()
Create an empty INI Config. |
Method Summary | |
---|---|
boolean |
add(String sectionName,
String key,
String value)
Add a key/value pair to a section. |
boolean |
addValue(String key,
String value)
Add a value for the key. |
private String |
advance(BufferedReader bin)
Get the next line from the input |
void |
clear()
Start over. |
List<String> |
getKeys()
Get the unmodifiable set of keys of the first section. |
private IniSection |
getOrCreateSection(String sectionName)
Get a section, creating it if necessary. |
IniSection |
getSection()
Get the first section. |
private IniSection |
getSection(String sectionName)
|
String |
getSectionName()
Get the name of the first section. |
String |
getSectionName(int index)
|
List<String> |
getSections()
Get an unmodifiable collection of the sections in this INI. |
private int |
getSplitPos(String line)
Does this line of text represent a key/value pair? |
String |
getValue(String key)
Get the first value for the key in the first section. |
String |
getValue(String key,
int index)
Get the value for the key specified by the index for the first section. |
String |
getValue(String sectionName,
String key)
Get the first value for the key specified by the index and the section. |
String |
getValue(String sectionName,
String key,
int index)
Get the value for the key specified by the index and the section. |
Collection<String> |
getValues(String key)
Get the values of a key of the first section. |
int |
getValueSize(String key)
Get the number of values for a key in the first section |
int |
getValueSize(String sectionName,
String key)
|
private boolean |
isCommentLine(String line)
Determine if the given line is a blank or a comment line. |
private boolean |
isSectionLine(String line)
Is this line a [section]? |
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 sectionName,
String key)
Remove the key if present. |
boolean |
remove(String sectionName,
String key,
String value)
Remove the value if present. |
boolean |
removeValue(String key)
Remove the key if present. |
boolean |
removeValue(String key,
String value)
Remove the value if present in the first section. |
boolean |
replace(String sectionName,
String key,
String value)
Replace a value for a key. |
boolean |
replaceValue(String key,
String value)
Replace a value for a key. |
void |
save(File file,
String encoding)
Save the INI to a file using the given encoding. |
private void |
save(Writer out)
Output the Ini to the given Writer. |
int |
size()
Get the number of sections |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private Map<String,IniSection> sectionMap
private List<String> list
private static final int MAX_BUFF_SIZE
private static final org.slf4j.Logger LOGGER
Constructor Detail |
---|
public Ini()
Method Detail |
---|
public void clear()
public int size()
public List<String> getSections()
public String getSectionName(int index)
public int getValueSize(String sectionName, String key)
public String getValue(String sectionName, String key, int index)
sectionName
- the name of the sectionkey
- the key for the sectionindex
- the index in the list of values
ArrayIndexOutOfBoundsException
- when the index is out of boundspublic String getValue(String sectionName, String key)
sectionName
- the name of the sectionkey
- the key for the section
ArrayIndexOutOfBoundsException
- when the index is out of boundspublic boolean add(String sectionName, String key, String value)
sectionName
- the name of the sectionkey
- the key for the sectionvalue
- the value for the key
true
if the element was added or already was presentpublic boolean replace(String sectionName, String key, String value)
sectionName
- the name of the sectionkey
- the key for the sectionvalue
- the value for the key
true
if the element was added or already was presentpublic boolean remove(String sectionName, String key, String value)
sectionName
- the name of the sectionkey
- the key for the sectionvalue
- the value for the key
public boolean remove(String sectionName, String key)
sectionName
- the name of the sectionkey
- the key for the section
public String getSectionName()
ArrayIndexOutOfBoundsException
- if there are no sectionspublic IniSection getSection()
public List<String> getKeys()
public Collection<String> getValues(String key)
key
- the key
public int getValueSize(String key)
key
- the key
public String getValue(String key, int index)
key
- the keyindex
- the index
ArrayIndexOutOfBoundsException
- when the index is out of boundspublic String getValue(String key)
key
- the key
ArrayIndexOutOfBoundsException
- when the index is out of boundspublic boolean addValue(String key, String value)
key
- the key for the sectionvalue
- the value for the key
public boolean removeValue(String key, String value)
key
- the key for the sectionvalue
- the value for the key
public boolean removeValue(String key)
key
- the key for the section
public boolean replaceValue(String key, String value)
key
- the key for the sectionvalue
- the value for the key
true
if the element was added or already was presentpublic 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 for this INI
IOException
public void save(File file, String encoding) throws IOException
file
- the file to loadencoding
- the encoding of the file
IOException
private void save(Writer out)
out
- the Writer to which this Ini should be writtenprivate IniSection getSection(String sectionName)
private IniSection getOrCreateSection(String sectionName)
sectionName
-
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
|
Copyright ยจ 2003-2015 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |