Skip to content

io microsphere util PropertyResourceBundleUtils

github-actions[bot] edited this page Mar 21, 2026 · 1 revision

PropertyResourceBundleUtils

Type: Class | Module: microsphere-java-core | Package: io.microsphere.util | Since: 1.0.0

Source: microsphere-java-core/src/main/java/io/microsphere/util/PropertyResourceBundleUtils.java

Overview

PropertyResourceBundle Utility class

Declaration

public abstract class PropertyResourceBundleUtils implements Utils

Author: Mercy

Version Information

  • Introduced in: 1.0.0
  • Current Project Version: 0.1.10-SNAPSHOT

Version Compatibility

This component is tested and compatible with the following Java versions:

Java Version Status
Java 8 ✅ Compatible
Java 11 ✅ Compatible
Java 17 ✅ Compatible
Java 21 ✅ Compatible
Java 25 ✅ Compatible

Examples

Method Examples

getBundle

// 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");
// 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;
getBundle(baseName, PropertyResourceBundleUtils.DEFAULT_ENCODING);
ResourceBundle bundle = PropertyResourceBundleUtils.getBundle("my.resources.Messages");

getBundle

// Load a ResourceBundle with a specific encoding (e.g., UTF-8)
ResourceBundle bundle = PropertyResourceBundleUtils.getBundle("my.resources.Messages", "UTF-8");

getBundle

// Load a ResourceBundle for a specific locale and encoding
ResourceBundle bundle = PropertyResourceBundleUtils.getBundle("my.resources.Messages", Locale.FRENCH, "UTF-8");

getBundle

// 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");

Usage

Maven Dependency

Add the following dependency to your pom.xml:

<dependency>
    <groupId>io.github.microsphere-projects</groupId>
    <artifactId>microsphere-java-core</artifactId>
    <version>${microsphere-java.version}</version>
</dependency>

Tip: Use the BOM (microsphere-java-dependencies) for consistent version management. See the Getting Started guide.

Import

import io.microsphere.util.PropertyResourceBundleUtils;

API Reference

Public Methods

Method Description
getBundle The system property name for specifying the default encoding used by PropertyResourceBundle.
getBundle Retrieves a resource bundle using the specified base name and character encoding.
getBundle Retrieves a resource bundle using the specified base name, locale, and character encoding.
getBundle Retrieves a resource bundle using the specified base name, locale, class loader, and character encoding.

Method Details

getBundle

public static ResourceBundle getBundle(String baseName)

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");
`

getBundle

public static ResourceBundle getBundle(String baseName, 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");
`

getBundle

public static ResourceBundle getBundle(String baseName, Locale locale, 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");
`

getBundle

public static ResourceBundle getBundle(String baseName, Locale locale, ClassLoader classLoader, 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");
`

See Also

  • PropertyResourceBundle

This documentation was auto-generated from the source code of microsphere-java.

Home

java-annotations

java-core

jdk-tools

lang-model

annotation-processor

java-test

Clone this wiki locally