|
|||||||||
| Home >> All >> com >> lutris >> [ util overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
com.lutris.util
Class ConfigFile

java.lang.Objectcom.lutris.util.ConfigFile
- public class ConfigFile
- extends java.lang.Object
ConfigFile is used to manipulate Multiserver configuration (.conf) files. Presents all configuration elements in the form of a keyed table. Configuration elements are grouped by string "keys" according to the function they configure. The syntax is described more formally below.
stream ::= entry | stream entry entry ::= key "=" value_list | comment | blank value_list ::= value | value_list "," value value ::= fragment | value "+" fragment fragment ::= key | quoted_string quoted_string ::= (C/C++ style quoted string) key ::= (A string matching [A-Za-z_\./][A-Za-z0-9_-\./]*) comment ::= "#" (any text up to a newline) blank ::= (A line containing only white space)In addition to the above syntax, some additional semantic rules apply. The operator "+" concatenates the fragment immediately to the left and to the right of it. Thus
ab + cd results in
abcd. The operator "," terminates one element and begins
the next element. Thus, the line val = hello, world
creates a configuration entry with the key "val" and the two elements
"hello", and "world". If the characters "+", ",", or "\" occur at
the end of a line, then the entry is continued on the next line.
Trailing and leading whitespaces are ignored, and multiple whitespace
characters are converted by default into a single space. The "+"
operator leaves no whitespace between operands.
Finally, within quoted strings, C-style backslash escapes are
recognized. These include "\n" for newline, "\t" for tab, etc.
An example configuration input file is given below.
#============================================================== # Sample.config #============================================================== LDAP_SERVERS[] = "server1.ldap.gov:338", "server2.ldap.gov:1000" USER_TIMEOUT = 3600 # seconds. Comments can follow on same line. STRANGE_ENTRY = "This is a long long long long long " + "long long line. Notice how the \"+\" " + "operator is used to break this line up " + "into more than one line in the config file." , "And this is the second element." # etc.
- Version:
- $Revision: 1.21.2.1.2.1 $
| Field Summary | |
private java.util.Hashtable |
comments
|
private Config |
config
|
private static char[] |
digits
|
private java.io.File |
file
The associated config file (if any) |
private java.util.Vector |
order
|
static java.lang.String |
TRAILING_COMMENT
The key under which the trailing comment is stored. |
| Constructor Summary | |
ConfigFile()
Default constructor for an empty config file. |
|
ConfigFile(java.io.File configFile)
Constructor from a File. |
|
ConfigFile(java.io.InputStream inputStream)
Constructor from an InputStream. |
|
ConfigFile(KeywordValueTable kvt)
Constructor from a KeywordValueTable. |
|
| Method Summary | |
void |
addEntry(java.lang.String key,
java.lang.String[] values,
java.lang.String comment)
Add an entry to the config file. |
void |
addEntry(java.lang.String key,
java.lang.String value,
java.lang.String comment)
Add an entry to the config file. |
private boolean |
containsWhiteSpace(java.lang.String str)
|
java.lang.String |
getComment(java.lang.String key)
Returns the comment associated with a given key, or null
if there is no comment. |
Config |
getConfig()
Returns the Config object representing the config data in the file. |
java.io.File |
getFile()
Get the associated file. |
private static java.lang.String |
quoteStr(java.lang.String s)
|
void |
removeEntry(java.lang.String key)
Remove an entry from the config file. |
void |
write()
Writes this config to the associated file. |
void |
write(java.io.OutputStream outputStream)
Writes out a config file to the OutputStream specified. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
config
private Config config
order
private java.util.Vector order
comments
private java.util.Hashtable comments
file
private java.io.File file
- The associated config file (if any)
TRAILING_COMMENT
public static final java.lang.String TRAILING_COMMENT
- The key under which the trailing comment is stored.
- See Also:
- Constant Field Values
digits
private static final char[] digits
| Constructor Detail |
ConfigFile
public ConfigFile()
- Default constructor for an empty config file.
ConfigFile
public ConfigFile(java.io.InputStream inputStream) throws ConfigException
- Constructor from an InputStream.
ConfigFile
public ConfigFile(java.io.File configFile) throws ConfigException, java.io.IOException
- Constructor from a File. Allows to later write back the
configuration to the same file.
ConfigFile
public ConfigFile(KeywordValueTable kvt) throws ConfigException
- Constructor from a KeywordValueTable.
| Method Detail |
getConfig
public Config getConfig()
- Returns the Config object representing the config data in the file.
getComment
public java.lang.String getComment(java.lang.String key)
- Returns the comment associated with a given key, or
nullif there is no comment. Pass inConfigFile.TRAILING_COMMENTto get the trailing comment.
addEntry
public void addEntry(java.lang.String key, java.lang.String[] values, java.lang.String comment) throws KeywordValueException
- Add an entry to the config file.
addEntry
public void addEntry(java.lang.String key, java.lang.String value, java.lang.String comment) throws KeywordValueException
- Add an entry to the config file.
removeEntry
public void removeEntry(java.lang.String key) throws KeywordValueException
- Remove an entry from the config file.
getFile
public java.io.File getFile()
- Get the associated file. If no file is associated with this
config,
nullis returned.
write
public void write()
throws java.io.IOException,
java.io.FileNotFoundException
- Writes this config to the associated file. If no file
is associated with this config, throws a
FileNotFoundException
write
public void write(java.io.OutputStream outputStream)
- Writes out a config file to the OutputStream specified.
Note that Objects other than String or String[] will
be converted into a String.
containsWhiteSpace
private boolean containsWhiteSpace(java.lang.String str)
quoteStr
private static final java.lang.String quoteStr(java.lang.String s)
|
|||||||||
| Home >> All >> com >> lutris >> [ util overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
JAVADOC
com.lutris.util.ConfigFile