Skip to content

io microsphere classloading StreamArtifactResourceResolver

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

StreamArtifactResourceResolver

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

Source: microsphere-java-core/src/main/java/io/microsphere/classloading/StreamArtifactResourceResolver.java

Overview

An abstract base class for implementing ArtifactResourceResolver that provides a skeletal implementation to resolve artifact resources from either a streamable resource (like a URL) or an archive file (like a JAR). This class handles common concerns such as:

- **Stream Handling:** Reads and processes artifact metadata from various sources including URLs, JAR files, and directories.
- **Error Handling:** Provides consistent error logging when reading or resolving artifacts fails.
- **Archive Support:** Offers utility methods to extract metadata from JARs or files within a directory structure.
- **Extensibility:** Declares abstract methods that subclasses must implement to define custom logic for identifying
    metadata locations and constructing artifact instances.

Key Abstract Methods

- `#isArtifactMetadata(String)`: Determines if the given relative path represents an artifact metadata file.
- `#resolve(URL, InputStream, ClassLoader)`: Constructs an artifact from the provided metadata stream.

Example Usage

`public class CustomStreamArtifactResourceResolver extends StreamArtifactResourceResolver {

    public CustomStreamArtifactResourceResolver(ClassLoader classLoader, int priority) {
        super(classLoader, priority);
    `

### Declaration

```java
public abstract class StreamArtifactResourceResolver extends AbstractArtifactResourceResolver
```

**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

```java
public class CustomStreamArtifactResourceResolver extends StreamArtifactResourceResolver {

    public CustomStreamArtifactResourceResolver(ClassLoader classLoader, int priority) {
        super(classLoader, priority);
    }

    @Override
    protected boolean isArtifactMetadata(String relativePath) {
        return relativePath.equals("META-INF/custom-artifact.properties");
    }

    @Override
    protected Artifact resolve(URL resourceURL, InputStream artifactMetadataData, ClassLoader classLoader) throws IOException {
        Properties properties = new Properties();
        properties.load(artifactMetadataData);
        return new DefaultArtifact(resourceURL, properties);
    }
}
```

## Usage

### Maven Dependency

Add the following dependency to your `pom.xml`:

```xml

    io.github.microsphere-projects
    microsphere-java-core
    ${microsphere-java.version}

```

> **Tip:** Use the BOM (`microsphere-java-dependencies`) for consistent version management. See the [Getting Started](https://github.com/microsphere-projects/microsphere-java#getting-started) guide.

### Import

```java
import io.microsphere.classloading.StreamArtifactResourceResolver;
```

## API Reference

### Public Methods

| Method | Description |
|--------|-------------|
| `resolve` |  |

## See Also

- `ArtifactResourceResolver`
- `AbstractArtifactResourceResolver`

---

*This documentation was auto-generated from the source code of [microsphere-java](https://github.com/microsphere-projects/microsphere-java).*

Home

java-annotations

java-core

jdk-tools

lang-model

annotation-processor

java-test

Clone this wiki locally