Class PropertiesUtil


  • public class PropertiesUtil
    extends Object
    Simple utilities for getting typed values from Properties.
    • Method Detail

      • getInt

        public static int getInt​(Properties config,
                                 String key,
                                 int defaultValue)
        Get integer from properties. This method throws an exception if the integer is not valid.
        Parameters:
        config - Properties
        key - key in Properties
        defaultValue - default value if value is not set
        Returns:
        default or value of key
      • getLong

        public static long getLong​(Properties config,
                                   String key,
                                   long defaultValue)
        Get long from properties. This method throws an exception if the long is not valid.
        Parameters:
        config - Properties
        key - key in Properties
        defaultValue - default value if value is not set
        Returns:
        default or value of key
      • getLong

        public static long getLong​(Properties config,
                                   String key,
                                   long defaultValue,
                                   org.slf4j.Logger logger)
        Get long from properties. This method only logs if the long is not valid.
        Parameters:
        config - Properties
        key - key in Properties
        defaultValue - default value if value is not set
        Returns:
        default or value of key
      • getBoolean

        public static boolean getBoolean​(Properties config,
                                         String key,
                                         boolean defaultValue)
        Get boolean from properties. This method returns true iff the parsed value is "true".
        Parameters:
        config - Properties
        key - key in Properties
        defaultValue - default value if value is not set
        Returns:
        default or value of key
      • flatten

        public static Properties flatten​(Properties config)
        Flatten a recursive Properties to a first level property map.

        In some cases, KafkaProducer#propsToMap for example, Properties is used purely as a HashTable without considering its default properties.

        Parameters:
        config - Properties to be flattened
        Returns:
        Properties without defaults; all properties are put in the first-level