Class PropertyResourceBundleUtils

    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.util.ResourceBundle getBundle​(java.lang.String baseName)
      Gets a resource bundle using the specified base name and the default encoding.
      static java.util.ResourceBundle getBundle​(java.lang.String baseName, java.lang.String encoding)
      Retrieves a resource bundle using the specified base name and character encoding.
      static java.util.ResourceBundle getBundle​(java.lang.String baseName, java.util.Locale locale, java.lang.ClassLoader classLoader, java.lang.String encoding)
      Retrieves a resource bundle using the specified base name, locale, class loader, and character encoding.
      static java.util.ResourceBundle getBundle​(java.lang.String baseName, java.util.Locale locale, java.lang.String encoding)
      Retrieves a resource bundle using the specified base name, locale, and character encoding.
      • Methods inherited from class java.lang.Object

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

      • DEFAULT_ENCODING_PROPERTY_NAME

        public static final java.lang.String DEFAULT_ENCODING_PROPERTY_NAME
        The system property name for specifying the default encoding used by PropertyResourceBundle.

        This property is typically used to set the character encoding for reading properties files. If not explicitly set, the value of this property defaults to the platform's file encoding (SystemUtils.FILE_ENCODING).

        Example Usage

        
         // Setting the default encoding to UTF-8 programmatically
         System.setProperty(PropertyResourceBundleUtils.DEFAULT_ENCODING_PROPERTY_NAME, "UTF-8");
        
         // Then using it when loading a bundle
         ResourceBundle bundle = PropertyResourceBundleUtils.getBundle("my.resources.Messages");
         
        See Also:
        PropertyResourceBundle, SystemUtils.FILE_ENCODING, Constant Field Values
      • DEFAULT_ENCODING

        public static final java.lang.String DEFAULT_ENCODING
        The default encoding for PropertyResourceBundle, retrieved from the system property specified by DEFAULT_ENCODING_PROPERTY_NAME. If not explicitly set, it falls back to the platform's file encoding (SystemUtils.FILE_ENCODING).

        Example Usage

        
         // Programmatically setting the default encoding to UTF-8
         System.setProperty(PropertyResourceBundleUtils.DEFAULT_ENCODING_PROPERTY_NAME, "UTF-8");
        
         // Getting the default encoding
         String encoding = PropertyResourceBundleUtils.DEFAULT_ENCODING;
         
    • Method Detail

      • getBundle

        @Nonnull
        public static java.util.ResourceBundle getBundle​(java.lang.String baseName)
        Gets a resource bundle using the specified base name and the default encoding.

        ResourceBundle.getBundle(String, Locale) with default file encoding encoding and default Locale under Thread context ClassLoader

        This method is a convenience shortcut for:

        
         getBundle(baseName, PropertyResourceBundleUtils.DEFAULT_ENCODING);
         

        Example Usage

        
         ResourceBundle bundle = PropertyResourceBundleUtils.getBundle("my.resources.Messages");
         
        Parameters:
        baseName - the base name of the resource bundle, a fully qualified class name
        Returns:
        the resource bundle
        Throws:
        java.lang.NullPointerException - if baseName is null
        java.util.MissingResourceException - if no resource bundle for the specified base name can be found
        java.lang.IllegalArgumentException - if the given control doesn't perform properly (e.g., control.getCandidateLocales returns null)
      • getBundle

        @Nonnull
        public static java.util.ResourceBundle getBundle​(java.lang.String baseName,
                                                         java.lang.String encoding)
        Retrieves a resource bundle using the specified base name and character encoding.

        This method loads the resource bundle with the given base name and uses the specified encoding for reading the properties file. It uses the default locale (Locale.getDefault()) and the thread context class loader to locate and load the bundle.

        Example Usage

        
         // Load a ResourceBundle with a specific encoding (e.g., UTF-8)
         ResourceBundle bundle = PropertyResourceBundleUtils.getBundle("my.resources.Messages", "UTF-8");
         
        Parameters:
        baseName - the base name of the resource bundle, typically a fully qualified class name
        encoding - the character encoding used to read the properties file, such as "UTF-8"
        Returns:
        the loaded resource bundle
        Throws:
        java.lang.NullPointerException - if the baseName or encoding is null
        java.util.MissingResourceException - if no resource bundle can be found for the specified base name
        java.lang.IllegalArgumentException - if the encoding is not supported or the control object behaves improperly
      • getBundle

        @Nonnull
        public static java.util.ResourceBundle getBundle​(java.lang.String baseName,
                                                         java.util.Locale locale,
                                                         java.lang.String encoding)
        Retrieves a resource bundle using the specified base name, locale, and character encoding.

        This method loads the resource bundle with the given base name and locale, using the specified encoding for reading the properties file. It uses the thread context class loader to locate and load the bundle.

        Example Usage

        
         // Load a ResourceBundle for a specific locale and encoding
         ResourceBundle bundle = PropertyResourceBundleUtils.getBundle("my.resources.Messages", Locale.FRENCH, "UTF-8");
         
        Parameters:
        baseName - the base name of the resource bundle, typically a fully qualified class name
        locale - the locale for which a resource bundle is desired
        encoding - the character encoding used to read the properties file, such as "UTF-8"
        Returns:
        the loaded resource bundle
        Throws:
        java.lang.NullPointerException - if the baseName, locale, or encoding is null
        java.util.MissingResourceException - if no resource bundle can be found for the specified base name and locale
        java.lang.IllegalArgumentException - if the encoding is not supported or the control object behaves improperly
      • getBundle

        @Nonnull
        public static java.util.ResourceBundle getBundle​(java.lang.String baseName,
                                                         java.util.Locale locale,
                                                         java.lang.ClassLoader classLoader,
                                                         java.lang.String encoding)
        Retrieves a resource bundle using the specified base name, locale, class loader, and character encoding.

        This method loads the resource bundle with the given base name and locale, using the specified class loader and character encoding for reading the properties file.

        Example Usage

        
         // Load a ResourceBundle with a specific locale, class loader, and encoding
         ClassLoader loader = MyClass.class.getClassLoader();
         ResourceBundle bundle = PropertyResourceBundleUtils.getBundle("my.resources.Messages", Locale.GERMAN, loader, "UTF-8");
         
        Parameters:
        baseName - the base name of the resource bundle, typically a fully qualified class name
        locale - the locale for which a resource bundle is desired
        classLoader - the class loader to use for loading the bundle
        encoding - the character encoding used to read the properties file, such as "UTF-8"
        Returns:
        the loaded resource bundle
        Throws:
        java.lang.NullPointerException - if any of the parameters (baseName, locale, classLoader, encoding) is null
        java.util.MissingResourceException - if no resource bundle can be found for the specified base name and locale
        java.lang.IllegalArgumentException - if the encoding is not supported or the control object behaves improperly