Class PropertiesUtil



  • public final class PropertiesUtil
    extends Object
    Consider this class private.

    Helps access properties. This utility provides a method to override system properties by specifying properties in a properties file.

    • Constructor Detail

      • PropertiesUtil

        public PropertiesUtil(Properties props)
        Constructs a PropertiesUtil using a given Properties object as its source of defined properties.
        Parameters:
        props - the Properties to use by default
      • PropertiesUtil

        public PropertiesUtil(String propertiesFileName)
        Constructs a PropertiesUtil for a given properties file name on the classpath. The properties specified in this file are used by default. If a property is not defined in this file, then the equivalent system property is used.
        Parameters:
        propertiesFileName - the location of properties file to load
    • Method Detail

      • getProperties

        public static PropertiesUtil getProperties()
        Returns the PropertiesUtil used by Log4j.
        Returns:
        the main Log4j PropertiesUtil instance.
      • getStringProperty

        public String getStringProperty(String name)
        Gets the named property as a String.
        Parameters:
        name - the name of the property to look up
        Returns:
        the String value of the property or null if undefined.
      • getIntegerProperty

        public int getIntegerProperty(String name,
                                      int defaultValue)
        Gets the named property as an integer.
        Parameters:
        name - the name of the property to look up
        defaultValue - the default value to use if the property is undefined
        Returns:
        the parsed integer value of the property or defaultValue if it was undefined or could not be parsed.
      • getLongProperty

        public long getLongProperty(String name,
                                    long defaultValue)
        Gets the named property as a long.
        Parameters:
        name - the name of the property to look up
        defaultValue - the default value to use if the property is undefined
        Returns:
        the parsed long value of the property or defaultValue if it was undefined or could not be parsed.
      • getStringProperty

        public String getStringProperty(String name,
                                        String defaultValue)
        Gets the named property as a String.
        Parameters:
        name - the name of the property to look up
        defaultValue - the default value to use if the property is undefined
        Returns:
        the String value of the property or defaultValue if undefined.
      • getBooleanProperty

        public boolean getBooleanProperty(String name)
        Gets the named property as a boolean value. If the property matches the string "true" (case-insensitive), then it is returned as the boolean value true. Any other non- null text in the property is considered false.
        Parameters:
        name - the name of the property to look up
        Returns:
        the boolean value of the property or false if undefined.
      • getBooleanProperty

        public boolean getBooleanProperty(String name,
                                          boolean defaultValue)
        Gets the named property as a boolean value.
        Parameters:
        name - the name of the property to look up
        defaultValue - the default value to use if the property is undefined
        Returns:
        the boolean value of the property or defaultValue if undefined.
      • getSystemProperties

        public static Properties getSystemProperties()
        Return the system properties or an empty Properties object if an error occurs.
        Returns:
        The system properties.
      • extractSubset

        public static Properties extractSubset(Properties properties,
                                               String prefix)
        Extracts properties that start with or are equals to the specific prefix and returns them in a new Properties object with the prefix removed.
        Parameters:
        properties - The Properties to evaluate.
        prefix - The prefix to extract.
        Returns:
        The subset of properties.
      • isOsWindows

        public boolean isOsWindows()
        Returns true if system properties tell us we are running on Windows.
        Returns:
        true if system properties tell us we are running on Windows.