Class ClassIndexReader
java.lang.Object
cloud.opencode.base.classloader.index.ClassIndexReader
Class Index Reader - Loads a pre-built class index from the classpath
类索引读取器 - 从 classpath 加载预构建的类索引
Reads the JSON index file produced by ClassIndexWriter and
validates it against the current classpath hash for staleness detection.
读取由 ClassIndexWriter 生成的 JSON 索引文件,
并通过当前 classpath 哈希值进行陈旧检测验证。
Usage Examples | 使用示例:
Optional<ClassIndex> index = ClassIndexReader.load();
if (index.isPresent() && ClassIndexReader.isValid(index.get())) {
// use index
}
Security | 安全性:
- Thread-safe: Yes - 线程安全: 是
- Since:
- JDK 25, opencode-base-classloader V1.0.3
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidDeprecated, for removal: This API element is subject to removal in a future version.static voidInvalidate the singleton cache, forcing the nextload()call to re-read the index from classpath.static booleanisValid(ClassIndex index) Check whether the index is still valid by comparing its classpath hash with the current one.static Optional<ClassIndex> load()Load the class index from the default classpath location using the context class loader 使用上下文类加载器从默认 classpath 位置加载类索引static Optional<ClassIndex> load(ClassLoader classLoader) Load the class index from the default classpath location using the specified class loader 使用指定的类加载器从默认 classpath 位置加载类索引
-
Method Details
-
load
Load the class index from the default classpath location using the context class loader 使用上下文类加载器从默认 classpath 位置加载类索引- Returns:
- the loaded index, or empty if not found or version incompatible | 加载的索引,未找到或版本不兼容则返回 empty
-
load
Load the class index from the default classpath location using the specified class loader 使用指定的类加载器从默认 classpath 位置加载类索引- Parameters:
classLoader- class loader to use for resource lookup | 用于资源查找的类加载器- Returns:
- the loaded index, or empty if not found or version incompatible | 加载的索引,未找到或版本不兼容则返回 empty
-
isValid
Check whether the index is still valid by comparing its classpath hash with the current one. If invalid, the cached index is automatically cleared so that subsequentload()calls will re-read from classpath. 通过比较 classpath 哈希值与当前值来检查索引是否仍然有效。 若无效,自动清除缓存索引,以便后续load()调用重新从 classpath 读取。- Parameters:
index- the class index to validate | 要验证的类索引- Returns:
- true if the classpath hash matches | 如果 classpath 哈希值匹配则返回 true
-
invalidateCache
-
clearCache
Deprecated, for removal: This API element is subject to removal in a future version.UseinvalidateCache()insteadClear the singleton cache (useful for testing) 清除单例缓存(便于测试)
-
invalidateCache()instead