Skip to content

io microsphere util PropertyResourceBundleControl

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

PropertyResourceBundleControl

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

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

Overview

A ResourceBundle.Control implementation for loading property-based resource bundles with customizable character encoding.

PropertyResourceBundleControl allows specifying the character encoding used when reading properties files, ensuring correct interpretation of non-ASCII characters. By default, it uses the platform's default encoding unless explicitly configured otherwise.

Example Usage

// Create a control with UTF-8 encoding
ResourceBundle.Control utf8Control = new PropertyResourceBundleControl("UTF-8");

// Load a resource bundle using the custom control
ResourceBundle bundle = ResourceBundle.getBundle("my.resources.Messages", Locale.US, utf8Control);

This class is thread-safe and can be reused across multiple calls to ResourceBundle#getBundle(String, ResourceBundle.Control).

Declaration

public class PropertyResourceBundleControl extends ResourceBundle.Control

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

// Create a control with UTF-8 encoding
ResourceBundle.Control utf8Control = new PropertyResourceBundleControl("UTF-8");

// Load a resource bundle using the custom control
ResourceBundle bundle = ResourceBundle.getBundle("my.resources.Messages", Locale.US, utf8Control);

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.PropertyResourceBundleControl;

API Reference

Public Methods

Method Description
getEncoding The suffix of the properties file
newControl Creates a new instance of PropertyResourceBundleControl if absent.

Method Details

getEncoding

public String getEncoding()

The suffix of the properties file / public static final String SUFFIX = "properties";

private static final ConcurrentMap encodingControlMap = new ConcurrentHashMap();

/** The singleton instance of PropertyResourceBundleControl as default / public static final PropertyResourceBundleControl DEFAULT_CONTROL;

static { DEFAULT_CONTROL = new PropertyResourceBundleControl(); // Add a Control as default encodingControlMap.put(DEFAULT_CONTROL.getEncoding(), DEFAULT_CONTROL); // Add "UTF-8" Control newControl("UTF-8"); }

private final String encoding;

protected PropertyResourceBundleControl() throws UnsupportedCharsetException { this(DEFAULT_ENCODING); }

/**

newControl

public static ResourceBundle.Control newControl(final String encoding)

Creates a new instance of PropertyResourceBundleControl if absent.

See Also

  • PropertyResourceBundle
  • ResourceBundle.Control

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