Class PropertyReader


  • public class PropertyReader
    extends java.lang.Object
    This class provides helper operations for reading typed properties out of Java Properties files, or out of the Java environment.
    • Constructor Summary

      Constructors 
      Constructor Description
      PropertyReader()  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static int getIntProperty​(java.util.Properties properties, java.lang.String propertyName, int defaultValue)
      Retrieves an integer-valued property, possibly with a scale modifier, from the specified collection of properties.
      static long getLongProperty​(java.util.Properties properties, java.lang.String propertyName, long defaultValue)
      Retrieves a long-integer-valued property, possibly with a scale modifier, from the specified collection of properties.
      private static int getScale​(java.lang.String str)
      Some properties can be a number plus a scale, such as "1024m" or "1G".
      int getSystemIntProperty​(java.lang.String propertyName, int defaultValue)
      Retrieves an integer-valued property, possibly with a scale modifier, from the system properties.
      long getSystemLongProperty​(java.lang.String propertyName, long defaultValue)
      Retrieves a long-integer-valued property, possibly with a scale modifier, from the system properties.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • PropertyReader

        public PropertyReader()
    • Method Detail

      • getScale

        private static int getScale​(java.lang.String str)
        Some properties can be a number plus a scale, such as "1024m" or "1G". This helper function pulls the scale indicator off of the end of the string and computes a scale from it. Note that this method does not flag invalid scale values!
        Parameters:
        str - a string that may or may not end with a scale
        Returns:
        the scale indicated by the string
      • getIntProperty

        public static int getIntProperty​(java.util.Properties properties,
                                         java.lang.String propertyName,
                                         int defaultValue)
        Retrieves an integer-valued property, possibly with a scale modifier, from the specified collection of properties.
        Parameters:
        properties - the collection of properties to read from
        propertyName - the name of the property
        defaultValue - the default value for the property, if absent
        Returns:
        the integer property value, or default if the property is absent
      • getLongProperty

        public static long getLongProperty​(java.util.Properties properties,
                                           java.lang.String propertyName,
                                           long defaultValue)
        Retrieves a long-integer-valued property, possibly with a scale modifier, from the specified collection of properties.
        Parameters:
        properties - the collection of properties to read from
        propertyName - the name of the property
        defaultValue - the default value for the property, if absent
        Returns:
        the long property value, or default if the property is absent
      • getSystemIntProperty

        public int getSystemIntProperty​(java.lang.String propertyName,
                                        int defaultValue)
        Retrieves an integer-valued property, possibly with a scale modifier, from the system properties.
        Parameters:
        propertyName - the name of the property
        defaultValue - the default value for the property, if absent
        Returns:
        the integer property value, or default if the property is absent
      • getSystemLongProperty

        public long getSystemLongProperty​(java.lang.String propertyName,
                                          long defaultValue)
        Retrieves a long-integer-valued property, possibly with a scale modifier, from the system properties.
        Parameters:
        propertyName - the name of the property
        defaultValue - the default value for the property, if absent
        Returns:
        the long property value, or default if the property is absent