|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectedu.ntnu.item.jt.configloader.PropertiesReader
public class PropertiesReader
Singleton responsible for maintaining a Properties object. Provides static access via getters. Contains logic for reading a properties file from disk. The properties reader is only intended as a means for providing access to constants, and thus does not provide any setProperty() functions.
Properties
Method Summary | |
---|---|
boolean |
getBool(String key,
boolean defaultValue)
Reads the value stored with a given key and attempts to cast it to boolean. |
double |
getDouble(String key,
double defaultValue)
Reads the value stored with a given key and attempts to cast it to double. |
static PropertiesReader |
getInstance()
Returns the properties reader instance. |
int |
getInt(String key,
int defaultValue)
Reads the value stored with a given key and attempts to cast it to int. |
String |
getString(String key,
String defaultValue)
Attempts to read the string associated with a given key. |
static PropertiesReader |
initialize(String configFile)
Initialize a properties reader object, reading the properties from a given location on the local file system. |
static void |
main(String[] args)
Contains simple test reads. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static PropertiesReader initialize(String configFile) throws AlreadyInitializedException, IOException
configFile
- path to the properties file on the local file system. Note that any backslashes will have to be escaped. For example "c:\powerscan\powerscan.properties" becomes "c:\\powerscan\\powerscan.properties". The file will have to be structured on a format accepted by the java Properties class.
AlreadyInitializedException
- if the properties reader has already been initialized.
IOException
- if reading from the file failed. In this case, the properties reader may be initialized again, or calls to getInstance() will try to load the default properties file.Properties
public static PropertiesReader getInstance()
public int getInt(String key, int defaultValue)
key
- key from which to read the value.defaultValue
- default value to be returned if reading fails.
public double getDouble(String key, double defaultValue)
key
- key from which to read the value.defaultValue
- default value to be returned if reading fails.
public boolean getBool(String key, boolean defaultValue)
key
- key from which to read the value.defaultValue
- default value to be returned if reading fails.
public String getString(String key, String defaultValue)
key
- key from which to read the value.defaultValue
- default value to be returned if reading fails.
public static void main(String[] args) throws Exception
args
-
Exception
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |