|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object wyvern.common.util.InitFile
This class can read & write an INI-file, like java.util.Properties, but it preserves the structure of the file, including comments and whitespace. It's not as efficient as a Properties, so if you can bear to have your keys rearranged, that's what you should use.
Keys and values are currently case-sensitive.
Field Summary | |
protected java.lang.String |
DEFAULT_CATEGORY
|
Constructor Summary | |
InitFile()
Constructs a new InitFile with no file. |
|
InitFile(java.lang.String filename)
Constructs a new InitFile for the specified .ini file. |
Method Summary | |
java.util.Hashtable |
getProperties(java.lang.String cat)
Returns a list of the properties under a given category. |
java.lang.String |
getProperty(java.lang.String cat,
java.lang.String name)
Returns a value given the category and key: alias for readValue(). |
void |
load(java.io.BufferedReader in)
Loads from the specified BufferedReader. |
void |
load(java.io.InputStream input)
Loads from the specified input stream. |
void |
load(java.lang.String filename)
Reads the file into a data structure. |
static void |
main(java.lang.String[] args)
Tests the functionality. |
boolean |
readBoolean(java.lang.String cat,
java.lang.String key)
Returns a key's value as a boolean. |
int |
readInteger(java.lang.String cat,
java.lang.String key)
Returns a key's value as an integer. |
java.lang.String |
readString(java.lang.String cat,
java.lang.String key)
Returns the String value for the passed key. |
java.lang.String |
readValue(java.lang.String cat,
java.lang.String key)
Returns the (String) value for the passed key. |
void |
removeValue(java.lang.String cat,
java.lang.String key)
Removes a value from the file |
void |
save(java.lang.String filename)
Saves the current set of properties to the specified file. |
void |
writeBoolean(java.lang.String cat,
java.lang.String key,
boolean value)
Writes a boolean value for a given key. |
void |
writeInteger(java.lang.String cat,
java.lang.String key,
int value)
Writes an integer value for a given key. |
void |
writeString(java.lang.String cat,
java.lang.String key,
java.lang.String value)
Writes a new value for the passed key. |
void |
writeValue(java.lang.String cat,
java.lang.String key,
java.lang.String value)
Writes a new value for the passed key. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected final java.lang.String DEFAULT_CATEGORY
Constructor Detail |
public InitFile()
public InitFile(java.lang.String filename) throws java.io.IOException
java.io.IOException
- if the file can't be readMethod Detail |
public java.lang.String readValue(java.lang.String cat, java.lang.String key)
cat
- the category, null if it's not in a categorykey
- the key to look for
public java.lang.String readString(java.lang.String cat, java.lang.String key)
cat
- the category, null if it's not in a categorykey
- the key to look for
public int readInteger(java.lang.String cat, java.lang.String key)
cat
- the category, null if it's not in a categorykey
- the key to look for
java.lang.NumberFormatException
- if the value isn't an integerpublic boolean readBoolean(java.lang.String cat, java.lang.String key)
cat
- the category, null if it's not in a categorykey
- the key to look for
public void writeValue(java.lang.String cat, java.lang.String key, java.lang.String value)
cat
- the category, null if it's not in a categorykey
- the key to look forvalue
- the new value for the keypublic void removeValue(java.lang.String cat, java.lang.String key)
cat
- the category, null if it's not in a categorykey
- the keypublic void writeString(java.lang.String cat, java.lang.String key, java.lang.String value)
cat
- the category, null if it's not in a categorykey
- the key to look forvalue
- the new value for the keypublic void writeInteger(java.lang.String cat, java.lang.String key, int value)
cat
- the category, null if it's not in a categorykey
- the key to look forvalue
- the int value to writepublic void writeBoolean(java.lang.String cat, java.lang.String key, boolean value)
cat
- the category, null if it's not in a categorykey
- the key to look forvalue
- the boolean value to writepublic void load(java.lang.String filename) throws java.io.IOException
If the first line of the file isn't a category, all lines up to the first category found are placed in a category called [@default] internally. "[@default]" is never written back out to the file.
Internally the InitFile keeps a table of categories. Under each category is a list of the lines in that category. New entries to the category are added to the end. The category names are kept in a sequential list so their ordering can be preserved when writing the file.
filename
- the file to load
java.io.IOException
public void load(java.io.InputStream input) throws java.io.IOException
java.io.IOException
public void load(java.io.BufferedReader in) throws java.io.IOException
in
- input reader
java.io.IOException
public void save(java.lang.String filename) throws java.io.IOException
filename
- name to save to
java.io.IOException
public java.lang.String getProperty(java.lang.String cat, java.lang.String name)
public java.util.Hashtable getProperties(java.lang.String cat)
cat
- the initfile categorypublic static void main(java.lang.String[] args) throws java.io.IOException
args
- an array whose first entry is the filename to test.
java.io.IOException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |