Class PropertyBundle


  • public class PropertyBundle
    extends java.lang.Object
    The property bundle.

    It is similar to java.util.ResourceBundle, but they differ as follows.

    • It uses Maps.load(Map, InputStream) to load the properties. Thus, It is capable to handle UTF-16 and UTF-8 (but not ISO-8859-1).
    • The locator could be any object as long as it implements InputStream getResourceAsStream(String).
    • It supports only property files.
    • The getBundle method returns null if the resource not found, while ResourceBundle throws MissingResourceException.

    Instances of PropertyBundle are cached, so the performance is good. However, it implies the property file mapped by the giving class loader, name and locale is immutable. In other words, if you update the content of a property file, it might not be reflected to getString unless it is cleared out of the cache.

    Thread safe.

    Author:
    tomyeh
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected PropertyBundle​(java.lang.String baseName, java.util.Locale locale, Locator locator, boolean caseInsensitive)
      Constructor.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static PropertyBundle getBundle​(java.lang.String baseName, java.util.Locale locale)
      Gets a resource bundle using the specified base name, locale, and the default locator, Locators.getDefault().
      static PropertyBundle getBundle​(java.lang.String baseName, java.util.Locale locale, boolean caseInsensitive)
      Gets a resource bundle using the specified base name, locale, and the default locator, Locators.getDefault().
      static PropertyBundle getBundle​(java.lang.String baseName, java.util.Locale locale, Locator locator)
      Gets a resource bundle using the specified base name, locale, and locator.
      static PropertyBundle getBundle​(java.lang.String baseName, java.util.Locale locale, Locator locator, boolean caseInsensitive)
      Gets a resource bundle using the specified base name, locale, and locator.
      java.util.Locale getLocale()
      Returns the locale of the bundle, or null if it is the default.
      java.util.Map<java.lang.String,​java.lang.String> getProperties()
      Returns a map of all properties, (String key , String value).
      java.lang.String getProperty​(java.lang.String key)
      Returns the property for the given key from this resource bundle or one of its parents.
      • Methods inherited from class java.lang.Object

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

      • PropertyBundle

        protected PropertyBundle​(java.lang.String baseName,
                                 java.util.Locale locale,
                                 Locator locator,
                                 boolean caseInsensitive)
        Constructor.
        Parameters:
        caseInsensitive - whether the key used to access the map is case-insensitive. If true, all keys are converted to lower cases.
    • Method Detail

      • getBundle

        public static final PropertyBundle getBundle​(java.lang.String baseName,
                                                     java.util.Locale locale,
                                                     Locator locator,
                                                     boolean caseInsensitive)
        Gets a resource bundle using the specified base name, locale, and locator.
        Parameters:
        locator - the locator (never null). See Locators.getDefault().
        caseInsensitive - whether the key used to access the map is case-insensitive. If true, all keys are converted to lower cases.
        Returns:
        the bundle; null if not found
      • getBundle

        public static final PropertyBundle getBundle​(java.lang.String baseName,
                                                     java.util.Locale locale,
                                                     Locator locator)
        Gets a resource bundle using the specified base name, locale, and locator.
      • getBundle

        public static final PropertyBundle getBundle​(java.lang.String baseName,
                                                     java.util.Locale locale,
                                                     boolean caseInsensitive)
        Gets a resource bundle using the specified base name, locale, and the default locator, Locators.getDefault().
        Parameters:
        caseInsensitive - whether the key used to access the map is case-insensitive. If true, all keys are converted to lower cases.
        Returns:
        the bundle; null if not found
      • getBundle

        public static final PropertyBundle getBundle​(java.lang.String baseName,
                                                     java.util.Locale locale)
        Gets a resource bundle using the specified base name, locale, and the default locator, Locators.getDefault().
      • getProperty

        public final java.lang.String getProperty​(java.lang.String key)
        Returns the property for the given key from this resource bundle or one of its parents.
      • getProperties

        public final java.util.Map<java.lang.String,​java.lang.String> getProperties()
        Returns a map of all properties, (String key , String value).
      • getLocale

        public final java.util.Locale getLocale()
        Returns the locale of the bundle, or null if it is the default. Note: it is value might not be the same as the locale being passed to the constructor, because the constructor will do some fallback.