public final class Settings
extends java.lang.Object
| Modifier and Type | Class and Description |
|---|---|
static class |
Settings.KEYS
The collection of keys used within the properties file.
|
| Constructor and Description |
|---|
Settings()
Initialize the settings object.
|
Settings(java.util.Properties properties)
Initialize the settings object using the given properties.
|
Settings(@NotNull java.lang.String propertiesFilePath)
Initialize the settings object using the given properties file.
|
| Modifier and Type | Method and Description |
|---|---|
void |
cleanup()
Cleans up resources to prevent memory leaks.
|
void |
cleanup(boolean deleteTemporary)
Cleans up resources to prevent memory leaks.
|
java.lang.String[] |
getArray(@NotNull java.lang.String key)
Returns a list with the given key.
|
boolean |
getBoolean(@NotNull java.lang.String key)
Returns a boolean value from the properties file.
|
boolean |
getBoolean(@NotNull java.lang.String key,
boolean defaultValue)
Returns a boolean value from the properties file.
|
java.lang.String |
getConnectionString(java.lang.String connectionStringKey,
java.lang.String dbFileNameKey)
Returns a connection string from the configured properties.
|
java.io.File |
getDataDirectory()
Retrieves the primary data directory that is used for caching web
content.
|
protected java.io.File |
getDataFile(@NotNull java.lang.String key)
Returns a value from the properties file as a File object.
|
@Nullable java.io.File |
getFile(@NotNull java.lang.String key)
Returns a value from the properties file as a File object.
|
float |
getFloat(@NotNull java.lang.String key,
float defaultValue)
Returns a float value from the properties file.
|
java.io.File |
getH2DataDirectory()
Retrieves the H2 data directory - if the database has been moved to the
temp directory this method will return the temp directory.
|
int |
getInt(@NotNull java.lang.String key)
Returns an int value from the properties file.
|
int |
getInt(@NotNull java.lang.String key,
int defaultValue)
Returns an int value from the properties file.
|
long |
getLong(@NotNull java.lang.String key)
Returns a long value from the properties file.
|
protected java.lang.String |
getPrintableValue(@NotNull java.lang.String key,
java.lang.String value)
Obtains the printable/loggable value for a given key/value pair.
|
java.lang.String |
getString(@NotNull java.lang.String key)
Returns a value from the properties file.
|
java.lang.String |
getString(@NotNull java.lang.String key,
@Nullable java.lang.String defaultValue)
Returns a value from the properties file.
|
java.io.File |
getTempDirectory()
Returns the temporary directory.
|
java.io.File |
getTempFile(@NotNull java.lang.String prefix,
@NotNull java.lang.String extension)
Generates a new temporary file name that is guaranteed to be unique.
|
protected void |
initMaskedKeys()
Initializes the masked keys collection.
|
void |
mergeProperties(@NotNull java.io.File filePath)
Merges a new properties file into the current properties.
|
void |
mergeProperties(@NotNull java.io.InputStream stream)
Merges a new properties file into the current properties.
|
void |
mergeProperties(@NotNull java.lang.String filePath)
Merges a new properties file into the current properties.
|
void |
removeProperty(@NotNull java.lang.String key)
Removes a property from the local properties collection.
|
void |
setArrayIfNotEmpty(@NotNull java.lang.String key,
@Nullable java.util.List<java.lang.String> value)
Sets a property value only if the array value is not null and not empty.
|
void |
setArrayIfNotEmpty(@NotNull java.lang.String key,
@Nullable java.lang.String[] value)
Sets a property value only if the array value is not null and not empty.
|
void |
setBoolean(@NotNull java.lang.String key,
boolean value)
Sets a property value.
|
void |
setBooleanIfNotNull(@NotNull java.lang.String key,
@Nullable java.lang.Boolean value)
Sets a property value only if the value is not null.
|
void |
setFloat(@NotNull java.lang.String key,
float value)
Sets a float property value.
|
void |
setInt(@NotNull java.lang.String key,
int value)
Sets a property value.
|
void |
setIntIfNotNull(@NotNull java.lang.String key,
@Nullable java.lang.Integer value)
Sets a property value only if the value is not null.
|
void |
setString(@NotNull java.lang.String key,
@NotNull java.lang.String value)
Sets a property value.
|
void |
setStringIfNotEmpty(@NotNull java.lang.String key,
@Nullable java.lang.String value)
Sets a property value only if the value is not null and not empty.
|
void |
setStringIfNotNull(@NotNull java.lang.String key,
@Nullable java.lang.String value)
Sets a property value only if the value is not null.
|
public Settings()
public Settings(java.util.Properties properties)
properties - the properties to be used with this Settings instancepublic Settings(@NotNull
@NotNull java.lang.String propertiesFilePath)
propertiesFilePath - the path to the base properties file to loadpublic void cleanup()
public void cleanup(boolean deleteTemporary)
deleteTemporary - flag indicating whether any temporary directories
generated should be removedprotected java.lang.String getPrintableValue(@NotNull
@NotNull java.lang.String key,
java.lang.String value)
key - the property keyvalue - the property valueprotected void initMaskedKeys()
initialize(java.lang.String) method because a caller may use the
mergeProperties(java.io.File) to add additional properties after
the call to initialize.public void setString(@NotNull
@NotNull java.lang.String key,
@NotNull
@NotNull java.lang.String value)
key - the key for the propertyvalue - the value for the propertypublic void setStringIfNotNull(@NotNull
@NotNull java.lang.String key,
@Nullable
@Nullable java.lang.String value)
key - the key for the propertyvalue - the value for the propertypublic void setStringIfNotEmpty(@NotNull
@NotNull java.lang.String key,
@Nullable
@Nullable java.lang.String value)
key - the key for the propertyvalue - the value for the propertypublic void setArrayIfNotEmpty(@NotNull
@NotNull java.lang.String key,
@Nullable
@Nullable java.lang.String[] value)
key - the key for the propertyvalue - the value for the propertypublic void setArrayIfNotEmpty(@NotNull
@NotNull java.lang.String key,
@Nullable
@Nullable java.util.List<java.lang.String> value)
key - the key for the propertyvalue - the value for the propertypublic void setBoolean(@NotNull
@NotNull java.lang.String key,
boolean value)
key - the key for the propertyvalue - the value for the propertypublic void setBooleanIfNotNull(@NotNull
@NotNull java.lang.String key,
@Nullable
@Nullable java.lang.Boolean value)
key - the key for the propertyvalue - the value for the propertypublic void setFloat(@NotNull
@NotNull java.lang.String key,
float value)
key - the key for the propertyvalue - the value for the propertypublic void setInt(@NotNull
@NotNull java.lang.String key,
int value)
key - the key for the propertyvalue - the value for the propertypublic void setIntIfNotNull(@NotNull
@NotNull java.lang.String key,
@Nullable
@Nullable java.lang.Integer value)
key - the key for the propertyvalue - the value for the propertypublic void mergeProperties(@NotNull
@NotNull java.io.File filePath)
throws java.io.FileNotFoundException,
java.io.IOException
filePath - the path to the properties file to merge.java.io.FileNotFoundException - is thrown when the filePath points
to a non-existent filejava.io.IOException - is thrown when there is an exception
loading/merging the propertiespublic void mergeProperties(@NotNull
@NotNull java.lang.String filePath)
throws java.io.FileNotFoundException,
java.io.IOException
filePath - the path to the properties file to merge.java.io.FileNotFoundException - is thrown when the filePath points
to a non-existent filejava.io.IOException - is thrown when there is an exception
loading/merging the propertiespublic void mergeProperties(@NotNull
@NotNull java.io.InputStream stream)
throws java.io.IOException
stream - an Input Stream pointing at a properties file to mergejava.io.IOException - is thrown when there is an exception
loading/merging the properties@Nullable
public @Nullable java.io.File getFile(@NotNull
@NotNull java.lang.String key)
key - the key to lookup within the properties fileprotected java.io.File getDataFile(@NotNull
@NotNull java.lang.String key)
This method will check the configured base directory and will use this as the base of the file path. Additionally, if the base directory begins with a leading "[JAR]\" sequence with the path to the folder containing the JAR file containing this class.
key - the key to lookup within the properties filepublic java.lang.String getString(@NotNull
@NotNull java.lang.String key,
@Nullable
@Nullable java.lang.String defaultValue)
key - the key to lookup within the properties filedefaultValue - the default value for the requested propertypublic java.io.File getTempDirectory()
throws java.io.IOException
java.io.IOException - if any.public java.lang.String getString(@NotNull
@NotNull java.lang.String key)
key - the key to lookup within the properties filepublic java.lang.String[] getArray(@NotNull
@NotNull java.lang.String key)
If the property is not set then null will be returned.
key - the key to get from this
Settings.null if the key wasn't present.public void removeProperty(@NotNull
@NotNull java.lang.String key)
key - the property key to removepublic int getInt(@NotNull
@NotNull java.lang.String key)
throws InvalidSettingException
key - the key to lookup within the properties fileInvalidSettingException - is thrown
if there is an error retrieving the settingpublic int getInt(@NotNull
@NotNull java.lang.String key,
int defaultValue)
key - the key to lookup within the properties filedefaultValue - the default value to returnpublic long getLong(@NotNull
@NotNull java.lang.String key)
throws InvalidSettingException
key - the key to lookup within the properties fileInvalidSettingException - is thrown
if there is an error retrieving the settingpublic boolean getBoolean(@NotNull
@NotNull java.lang.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 boolean getBoolean(@NotNull
@NotNull java.lang.String key,
boolean defaultValue)
-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
existpublic float getFloat(@NotNull
@NotNull java.lang.String key,
float defaultValue)
-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
existpublic java.lang.String getConnectionString(java.lang.String connectionStringKey,
java.lang.String dbFileNameKey)
throws java.io.IOException,
InvalidSettingException
connectionStringKey - the property file key for the connection
stringdbFileNameKey - the settings key for the db filenamejava.io.IOException - thrown the data directory cannot be createdInvalidSettingException - thrown if there is an invalid settingpublic java.io.File getDataDirectory()
throws java.io.IOException
java.io.IOException - is thrown if an java.io.IOException occurs of
course...public java.io.File getH2DataDirectory()
throws java.io.IOException
java.io.IOException - is thrown if an java.io.IOException occurs of
course...public java.io.File getTempFile(@NotNull
@NotNull java.lang.String prefix,
@NotNull
@NotNull java.lang.String extension)
throws java.io.IOException
prefix - the prefix for the file name to generateextension - the extension of the generated file namejava.io.IOException - if any.Copyright© 2012-21 Jeremy Long. All Rights Reserved.