Skip to content

io microsphere annotation processor ResourceProcessor

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

ResourceProcessor

Type: Class | Module: microsphere-annotation-processor | Package: io.microsphere.annotation.processor | Since: 1.0.0

Source: microsphere-annotation-processor/src/main/java/io/microsphere/annotation/processor/ResourceProcessor.java

Overview

A processor class that provides a comprehensive and exception-safe mechanism for handling resources during annotation processing. It extends the capabilities of the FilerProcessor to manage both reading from and writing to resources using various I/O operations. This class abstracts away boilerplate code required for resource management, including opening/closing streams, handling exceptions, and caching accessed file objects to avoid redundant operations.

It supports functional-style interaction with resources through callback interfaces like ThrowableFunction, allowing custom logic to be applied on resources such as reading content, writing data, or manipulating streams in a type-safe manner.

The class also maintains an internal cache of accessed file objects to optimize performance by avoiding repeated calls to locate or create them. It handles both input (read) and output (write) operations seamlessly, offering convenience methods for common use cases like:

  • Processing resources via InputStream or Reader
  • Manipulating resources via OutputStream or Writer
  • Reading or modifying the content directly as CharSequence

Example Usage

// Creating an instance of ResourceProcessor
ResourceProcessor resourceProcessor = new ResourceProcessor(processingEnv, StandardLocation.SOURCE_OUTPUT);

// Reading content from a resource
Optional content = resourceProcessor.processInResourceContent("example.txt", CharBuffer::toString);

// Writing to a resource
resourceProcessor.processInResourceWriter("output.txt", writer -> {
    writer.write("Hello, World!");
});

// Processing an InputStream
resourceProcessor.processInResourceInputStream("data.bin", inputStream -> {
    // Process binary data
    return null;
});

Declaration

public class ResourceProcessor

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

// Creating an instance of ResourceProcessor
ResourceProcessor resourceProcessor = new ResourceProcessor(processingEnv, StandardLocation.SOURCE_OUTPUT);

// Reading content from a resource
Optional<String> content = resourceProcessor.processInResourceContent("example.txt", CharBuffer::toString);

// Writing to a resource
resourceProcessor.processInResourceWriter("output.txt", writer -> {
    writer.write("Hello, World!");
});

// Processing an InputStream
resourceProcessor.processInResourceInputStream("data.bin", inputStream -> {
    // Process binary data
    return null;
});

Usage

Maven Dependency

Add the following dependency to your pom.xml:

<dependency>
    <groupId>io.github.microsphere-projects</groupId>
    <artifactId>microsphere-annotation-processor</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.annotation.processor.ResourceProcessor;

API Reference

Public Methods

Method Description
processInResource
processInResource
getResource
processInResourceInputStream
processInResourceInputStream
processInResourceReader
processInResourceReader
processInResourceContent
processInResourceContent
processInResourceOutputStream
processInResourceOutputStream
processInResourceWriter
processInResourceWriter
exists

See Also

  • FilerProcessor

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