public final class Settings extends Object
| Modifier and Type | Class and Description |
|---|---|
static class |
Settings.KEYS
The collection of keys used within the properties file.
|
| Modifier and Type | Method and Description |
|---|---|
static void |
cleanup()
Cleans up resources to prevent memory leaks.
|
static void |
cleanup(boolean deleteTemporary)
Cleans up resources to prevent memory leaks.
|
static boolean |
getBoolean(String key)
Returns a boolean value from the properties file.
|
static boolean |
getBoolean(String key,
boolean defaultValue)
Returns a boolean value from the properties file.
|
static String |
getConnectionString(String connectionStringKey,
String dbFileNameKey,
String dbVersionKey)
Returns a connection string from the configured properties.
|
static File |
getDataDirectory()
Retrieves the directory that the JAR file exists in so that we can ensure we always use a common data directory for the
embedded H2 database.
|
protected static File |
getDataFile(String key)
Returns a value from the properties file as a File object.
|
static File |
getFile(String key)
Returns a value from the properties file as a File object.
|
static Settings |
getInstance()
Gets the underlying instance of the Settings object.
|
static int |
getInt(String key)
Returns an int value from the properties file.
|
static int |
getInt(String key,
int defaultValue)
Returns an int value from the properties file.
|
static long |
getLong(String key)
Returns a long value from the properties file.
|
static String |
getString(String key)
Returns a value from the properties file.
|
static String |
getString(String key,
String defaultValue)
Returns a value from the properties file.
|
static File |
getTempDirectory()
Returns the temporary directory.
|
static void |
initialize()
Initializes the thread local settings object.
|
static void |
initialize(String propertiesFilePath)
Initializes the thread local settings object.
|
static void |
mergeProperties(File filePath)
Merges a new properties file into the current properties.
|
static void |
mergeProperties(InputStream stream)
Merges a new properties file into the current properties.
|
static void |
mergeProperties(String filePath)
Merges a new properties file into the current properties.
|
static void |
removeProperty(String key)
Removes a property from the local properties collection.
|
static void |
setBoolean(String key,
boolean value)
Sets a property value.
|
static void |
setInstance(Settings instance)
Sets the instance of the Settings object to use in this thread.
|
static void |
setString(String key,
String value)
Sets a property value.
|
public static void initialize()
public static void initialize(String propertiesFilePath)
propertiesFilePath - the path to the base properties file to loadpublic static void cleanup()
public static void cleanup(boolean deleteTemporary)
deleteTemporary - flag indicating whether any temporary directories generated should be removedpublic static Settings getInstance()
public static void setInstance(Settings instance)
instance - the instance of the settings object to use in this threadpublic static void setString(String key, String value)
key - the key for the propertyvalue - the value for the propertypublic static void setBoolean(String key, boolean value)
key - the key for the propertyvalue - the value for the propertypublic static void mergeProperties(File filePath) throws FileNotFoundException, IOException
filePath - the path to the properties file to merge.FileNotFoundException - is thrown when the filePath points to a non-existent fileIOException - is thrown when there is an exception loading/merging the propertiespublic static void mergeProperties(String filePath) throws FileNotFoundException, IOException
filePath - the path to the properties file to merge.FileNotFoundException - is thrown when the filePath points to a non-existent fileIOException - is thrown when there is an exception loading/merging the propertiespublic static void mergeProperties(InputStream stream) throws IOException
stream - an Input Stream pointing at a properties file to mergeIOException - is thrown when there is an exception loading/merging the propertiespublic static File getFile(String key)
key - the key to lookup within the properties fileprotected static File getDataFile(String key)
key - the key to lookup within the properties filepublic static String getString(String key, String defaultValue)
key - the key to lookup within the properties filedefaultValue - the default value for the requested propertypublic static File getTempDirectory() throws IOException
IOException - thrown if the temporary directory does not exist and cannot be createdpublic static String getString(String key)
key - the key to lookup within the properties filepublic static void removeProperty(String key)
key - the property key to removepublic static int getInt(String key) throws InvalidSettingException
key - the key to lookup within the properties fileInvalidSettingException - is thrown if there is an error retrieving the settingpublic static int getInt(String key, int defaultValue)
key - the key to lookup within the properties filedefaultValue - the default value to returnpublic static long getLong(String key) throws InvalidSettingException
key - the key to lookup within the properties fileInvalidSettingException - is thrown if there is an error retrieving the settingpublic static boolean getBoolean(String key) throws InvalidSettingException
-Dprop=value argument this method will return the value from the system properties before the values in the
contained configuration file.key - the key to lookup within the properties fileInvalidSettingException - is thrown if there is an error retrieving the settingpublic static boolean getBoolean(String key, boolean defaultValue) throws InvalidSettingException
-Dprop=value argument this method will return the value from the system properties before the values in the
contained configuration file.key - the key to lookup within the properties filedefaultValue - the default value to return if the setting does not existInvalidSettingException - is thrown if there is an error retrieving the settingpublic static String getConnectionString(String connectionStringKey, String dbFileNameKey, String dbVersionKey) throws IOException, InvalidSettingException
connectionStringKey - the property file key for the connection stringdbFileNameKey - the settings key for the db filenamedbVersionKey - the settings key for the dbVersionIOException - thrown the data directory cannot be createdInvalidSettingException - thrown if there is an invalid settingpublic static File getDataDirectory() throws IOException
IOException - is thrown if an IOException occurs of course...Copyright© 2012-15 Jeremy Long. All Rights Reserved.