|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.comedia.util.CIniFile
Emulates Windows INI file interface. It loads and entire ini file into memory and allows all operations to be performed on the memory image. The image can then be written out to the disk file.
Example of usage:
CIniFile iniFile = new CIniFile("test.ini"); boolean p1 = iniFile.readBool("Section 1", "P1", false); System.out.println("P1 = " + p1); iniFile.writeBool("Section 1", "P1", !p1); System.out.println("Section 2, Parameter 1 = " + iniFile.readString("Other X", "Param1", "")); System.out.println("Section 2, Parameter 2 = " + iniFile.readInteger("Section 2", "P2", 123)); System.out.println("Section 2, Parameter 3 = " + iniFile.readDateTime("Section 2", "P3", new Date())); iniFile.writeString("Section 2", "P1", "..\"xxx\"..."); iniFile.writeDateTime("Section 2", "P3", new Date()); iniFile.flush();
Constructor Summary | |
CIniFile()
Constructs an empty class with default properties. |
|
CIniFile(java.io.File file)
Constructs this class with specified class name. |
|
CIniFile(java.lang.String fileName)
Constructs this class with specified class name. |
|
CIniFile(java.net.URL url)
Constructs this class with specified class name. |
Method Summary | |
void |
clear()
Removes all sections from this ini file. |
void |
deleteKey(java.lang.String section,
java.lang.String ident)
Removes the specified key from the section. |
void |
eraseSection(java.lang.String section)
Removes specified section from this ini file. |
void |
flush()
Flushes this ini file to disk file. |
boolean |
isSectionExists(java.lang.String section)
Tests if section exists in this ini file. |
void |
loadFromStream(java.io.InputStream stream)
Loads the content from the specified input stream. |
static void |
main(java.lang.String[] args)
The main procedure for test purposes. |
boolean |
readBool(java.lang.String section,
java.lang.String ident,
boolean def)
Reads boolean value from this ini file. |
java.util.Date |
readDateTime(java.lang.String section,
java.lang.String ident,
java.util.Date def)
Reads dateTime value from this ini file. |
double |
readFloat(java.lang.String section,
java.lang.String ident,
double def)
Reads float value from this ini file. |
int |
readInteger(java.lang.String section,
java.lang.String ident,
int def)
Reads integer value from this ini file. |
java.lang.String |
readString(java.lang.String section,
java.lang.String ident,
java.lang.String def)
Reads string value from this ini file. |
void |
rename(java.io.File file,
boolean reload)
Renames or reload this ini file. |
void |
rename(java.lang.String fileName,
boolean reload)
Renames or reload this ini file. |
void |
rename(java.net.URL url,
boolean reload)
Renames or reload this ini file. |
void |
saveToStream(java.io.OutputStream stream)
Saves ini file into output stream. |
java.lang.String |
unwrapString(java.lang.String s)
Converts a string from escape format limited with quotes into oridinary (local) presentation. |
boolean |
valueExists(java.lang.String section,
java.lang.String ident)
Tests if key exists in the specified section in this ini file. |
void |
writeBool(java.lang.String section,
java.lang.String ident,
boolean value)
Writes boolean value with specified key into the section in this ini file. |
void |
writeDateTime(java.lang.String section,
java.lang.String ident,
java.util.Date value)
Writes dateTime value with specified key into the section in this ini file. |
void |
writeFloat(java.lang.String section,
java.lang.String ident,
double value)
Writes float value with specified key into the section in this ini file. |
void |
writeInteger(java.lang.String section,
java.lang.String ident,
int value)
Writes integer value with specified key into the section in this ini file. |
void |
writeString(java.lang.String section,
java.lang.String ident,
java.lang.String value)
Writes string value with specified key into the section in this ini file. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public CIniFile()
public CIniFile(java.lang.String fileName) throws java.io.IOException
fileName
- a name of a ini file.public CIniFile(java.io.File file) throws java.io.IOException
file
- a file object of a ini file.public CIniFile(java.net.URL url) throws java.io.IOException
url
- an url which points to file.Method Detail |
public void clear()
public void deleteKey(java.lang.String section, java.lang.String ident)
section
- a name of the section.ident
- the name of removed key.public void eraseSection(java.lang.String section)
section
- the name of removed section.public boolean valueExists(java.lang.String section, java.lang.String ident)
section
- the name of the section.ident
- the name of the tested key.public boolean isSectionExists(java.lang.String section)
section
- teh name of the tested section.public void loadFromStream(java.io.InputStream stream) throws java.io.IOException
stream
- the input stream to read the ini file.public java.lang.String unwrapString(java.lang.String s)
s
- a string in escape format.public java.lang.String readString(java.lang.String section, java.lang.String ident, java.lang.String def)
section
- the name of the section.ident
- the key name of the value.def
- a default value, if this key is not exists.public void rename(java.lang.String fileName, boolean reload) throws java.io.IOException
fileName
- the new file name.reload
- if TRUE
the file will be reloaded with new
contents, otherwise it will be stored in the new file with old contents.public void rename(java.io.File file, boolean reload) throws java.io.IOException
file
- object the new file name.reload
- if TRUE
the file will be reloaded with new
contents, otherwise it will be stored in the new file with old contents.public void rename(java.net.URL url, boolean reload) throws java.io.IOException
url
- a new url of the file name.reload
- if TRUE
the file will be reloaded with new
contents, otherwise it will be stored in the new file with old contents.public void saveToStream(java.io.OutputStream stream) throws java.io.IOException
ouput
- stream to save this ini file.public void flush() throws java.io.IOException
public void writeString(java.lang.String section, java.lang.String ident, java.lang.String value)
section
- the name of the section.ident
- the key name of the value.value
- a value of the key.public int readInteger(java.lang.String section, java.lang.String ident, int def)
section
- the name of the section.ident
- the key name of the value.def
- a default value, if this key is not exists.public void writeInteger(java.lang.String section, java.lang.String ident, int value)
section
- the name of the section.ident
- the key name of the value.value
- a value of the key.public boolean readBool(java.lang.String section, java.lang.String ident, boolean def)
section
- the name of the section.ident
- the key name of the value.def
- a default value, if this key is not exists.public void writeBool(java.lang.String section, java.lang.String ident, boolean value)
section
- the name of the section.ident
- the key name of the value.value
- a value of the key.public double readFloat(java.lang.String section, java.lang.String ident, double def)
section
- the name of the section.ident
- the key name of the value.def
- a default value, if this key is not exists.public void writeFloat(java.lang.String section, java.lang.String ident, double value)
section
- the name of the section.ident
- the key name of the value.value
- a value of the key.public java.util.Date readDateTime(java.lang.String section, java.lang.String ident, java.util.Date def)
section
- the name of the section.ident
- the key name of the value.def
- a default value, if this key is not exists.public void writeDateTime(java.lang.String section, java.lang.String ident, java.util.Date value)
section
- the name of the section.ident
- the key name of the value.value
- a value of the key.public static void main(java.lang.String[] args)
args
- the command line arguments.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |