Class PropertiesConfigSource

java.lang.Object
cloud.opencode.base.config.source.PropertiesConfigSource
All Implemented Interfaces:
ConfigSource

public class PropertiesConfigSource extends Object implements ConfigSource
Properties File Configuration Source Properties文件配置源

Loads configuration from .properties files, supporting both classpath and filesystem resources.

从.properties文件加载配置,支持类路径和文件系统资源。

Features | 主要功能:

  • Classpath and filesystem support - 支持类路径和文件系统
  • Hot reload for file-based sources - 文件源支持热重载
  • UTF-8 encoding support - UTF-8编码支持
  • Last modified time tracking - 最后修改时间跟踪

Usage Examples | 使用示例:

// From classpath
ConfigSource source = new PropertiesConfigSource("application.properties", true);

// From filesystem
ConfigSource source = new PropertiesConfigSource(Path.of("/etc/app/config.properties"));

// Hot reload
if (source.supportsReload()) {
    source.reload();
}

Performance | 性能特性:

  • Time complexity: O(n) for loading - 时间复杂度: 加载为O(n)
  • Properties cached in memory - 属性缓存在内存中
  • Reload checks modification time - 重载检查修改时间

Security | 安全性:

  • Thread-safe: Yes - 线程安全: 是
  • Immutable properties map - 不可变属性映射
Since:
JDK 25, opencode-base-config V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Constructor Details

    • PropertiesConfigSource

      public PropertiesConfigSource(String resource, boolean classpath)
      Create properties source from classpath or filesystem 从类路径或文件系统创建属性源
      Parameters:
      resource - resource path | 资源路径
      classpath - true for classpath, false for filesystem | 类路径为true,文件系统为false
    • PropertiesConfigSource

      public PropertiesConfigSource(Path file)
      Create properties source from filesystem path 从文件系统路径创建属性源
      Parameters:
      file - file path | 文件路径
  • Method Details

    • getName

      public String getName()
      Description copied from interface: ConfigSource
      Get configuration source name 获取配置源名称
      Specified by:
      getName in interface ConfigSource
      Returns:
      source name | 源名称
    • getProperties

      public Map<String,String> getProperties()
      Description copied from interface: ConfigSource
      Get all configuration properties 获取所有配置属性

      Performance | 性能:

      This method should return a cached immutable map for best performance.

      此方法应返回缓存的不可变映射以获得最佳性能。

      Specified by:
      getProperties in interface ConfigSource
      Returns:
      configuration properties map | 配置属性映射
    • getPriority

      public int getPriority()
      Description copied from interface: ConfigSource
      Get configuration source priority (higher number = higher priority) 获取配置源优先级(数值越大优先级越高)

      Default Priorities | 默认优先级:

      • CommandLine: 200
      • Environment: 100
      • Properties/YAML: 50
      • InMemory: 10
      Specified by:
      getPriority in interface ConfigSource
      Returns:
      priority value | 优先级值
    • supportsReload

      public boolean supportsReload()
      Description copied from interface: ConfigSource
      Check if source supports hot reload 检查源是否支持热重载
      Specified by:
      supportsReload in interface ConfigSource
      Returns:
      true if hot reload supported | 如果支持热重载返回true
    • reload

      public void reload()
      Description copied from interface: ConfigSource
      Reload configuration from source 从源重新加载配置

      This method is called when hot reload is enabled.

      启用热重载时会调用此方法。

      Specified by:
      reload in interface ConfigSource