Class StreamArtifactResourceResolver

  • All Implemented Interfaces:
    ArtifactResourceResolver, Prioritized, java.lang.Comparable<Prioritized>
    Direct Known Subclasses:
    ManifestArtifactResourceResolver, MavenArtifactResourceResolver

    public abstract class StreamArtifactResourceResolver
    extends AbstractArtifactResourceResolver
    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

    Example Usage

    {@code
     public class CustomStreamArtifactResourceResolver extends StreamArtifactResourceResolver {
    
         public CustomStreamArtifactResourceResolver(ClassLoader classLoader, int priority) {
             super(classLoader, priority);
         }
    Since:
    1.0.0
    Author:
    Mercy
    See Also:
    ArtifactResourceResolver, AbstractArtifactResourceResolver
    • Constructor Detail

      • StreamArtifactResourceResolver

        public StreamArtifactResourceResolver​(int priority)
      • StreamArtifactResourceResolver

        public StreamArtifactResourceResolver​(java.lang.ClassLoader classLoader,
                                              int priority)
    • Method Detail

      • resolve

        public final Artifact resolve​(java.net.URL resourceURL)
        Description copied from interface: ArtifactResourceResolver
        Resolve an instance Artifact from the resource of artifact.
        Parameters:
        resourceURL - the resource of artifact, it may the archive file or the directory
        Returns:
        an instance Artifact if found, otherwise null
      • readArtifactMetadataDataFromResource

        @Nullable
        protected java.io.InputStream readArtifactMetadataDataFromResource​(java.net.URL resourceURL,
                                                                           java.lang.ClassLoader classLoader)
                                                                    throws java.io.IOException
        Throws:
        java.io.IOException
      • readArtifactMetadataDataFromArchiveFile

        @Nullable
        protected java.io.InputStream readArtifactMetadataDataFromArchiveFile​(java.io.File archiveFile)
                                                                       throws java.io.IOException
        Throws:
        java.io.IOException
      • readArtifactMetadataDataFromFile

        @Nullable
        protected java.io.InputStream readArtifactMetadataDataFromFile​(java.io.File archiveFile)
                                                                throws java.io.IOException
        Throws:
        java.io.IOException
      • readArtifactMetadataDataFromDirectory

        @Nullable
        protected java.io.InputStream readArtifactMetadataDataFromDirectory​(java.io.File directory)
                                                                     throws java.io.IOException
        Throws:
        java.io.IOException
      • findArtifactMetadataEntry

        protected java.util.jar.JarEntry findArtifactMetadataEntry​(java.util.jar.JarFile jarFile)
                                                            throws java.io.IOException
        Throws:
        java.io.IOException
      • findArtifactMetadata

        protected java.io.File findArtifactMetadata​(java.io.File directory)
                                             throws java.io.IOException
        Throws:
        java.io.IOException
      • isArtifactMetadataEntry

        protected boolean isArtifactMetadataEntry​(java.util.jar.JarEntry jarEntry)
      • isArtifactMetadataFile

        protected boolean isArtifactMetadataFile​(java.io.File directory,
                                                 java.io.File file)
      • isArtifactMetadata

        protected abstract boolean isArtifactMetadata​(java.lang.String relativePath)
      • resolve

        protected abstract Artifact resolve​(java.net.URL resourceURL,
                                            java.io.InputStream artifactMetadataData,
                                            java.lang.ClassLoader classLoader)
                                     throws java.io.IOException
        Throws:
        java.io.IOException