public final class PropertiesUtil extends Object
Helps access properties. This utility provides a method to override system properties by specifying properties in a properties file.
Constructor and Description |
---|
PropertiesUtil(Properties props)
Constructs a PropertiesUtil using a given Properties object as its source of defined properties.
|
PropertiesUtil(String propertiesFileName)
Constructs a PropertiesUtil for a given properties file name on the classpath.
|
Modifier and Type | Method and Description |
---|---|
boolean |
getBooleanProperty(String name)
Gets the named property as a boolean value.
|
boolean |
getBooleanProperty(String name,
boolean defaultValue)
Gets the named property as a boolean value.
|
int |
getIntegerProperty(String name,
int defaultValue)
Gets the named property as an integer.
|
long |
getLongProperty(String name,
long defaultValue)
Gets the named property as a long.
|
static PropertiesUtil |
getProperties()
Returns the PropertiesUtil used by Log4j.
|
String |
getStringProperty(String name)
Gets the named property as a String.
|
String |
getStringProperty(String name,
String defaultValue)
Gets the named property as a String.
|
static Properties |
getSystemProperties()
Return the system properties or an empty Properties object if an error occurs.
|
public PropertiesUtil(Properties props)
props
- the Properties to use by defaultpublic PropertiesUtil(String propertiesFileName)
propertiesFileName
- the location of properties file to loadpublic static PropertiesUtil getProperties()
public String getStringProperty(String name)
name
- the name of the property to look upnull
if undefined.public int getIntegerProperty(String name, int defaultValue)
name
- the name of the property to look updefaultValue
- the default value to use if the property is undefineddefaultValue
if it was undefined or could not be
parsed.public long getLongProperty(String name, long defaultValue)
name
- the name of the property to look updefaultValue
- the default value to use if the property is undefineddefaultValue
if it was undefined or could not be
parsed.public String getStringProperty(String name, String defaultValue)
name
- the name of the property to look updefaultValue
- the default value to use if the property is undefineddefaultValue
if undefined.public boolean getBooleanProperty(String name)
"true"
(case-insensitive),
then it is returned as the boolean value true
. Any other non-null
text in the property is
considered false
.name
- the name of the property to look upfalse
if undefined.public boolean getBooleanProperty(String name, boolean defaultValue)
name
- the name of the property to look updefaultValue
- the default value to use if the property is undefineddefaultValue
if undefined.public static Properties getSystemProperties()
Copyright © 1999-2021 Apache Software Foundation. All Rights Reserved.
Apache Logging, Apache Log4j, Log4j, Apache, the Apache feather logo, the Apache Logging project logo, and the Apache Log4j logo are trademarks of The Apache Software Foundation.