Class ServiceLoaderURLStreamHandlerFactory

  • All Implemented Interfaces:
    java.net.URLStreamHandlerFactory

    public class ServiceLoaderURLStreamHandlerFactory
    extends DelegatingURLStreamHandlerFactory
    A URLStreamHandlerFactory implementation that uses the JDK's ServiceLoader to load and compose multiple delegates for creating URLStreamHandler instances.

    ServiceLoaderURLStreamHandlerFactory extends from DelegatingURLStreamHandlerFactory, delegating to a composite chain of factories and handlers discovered via service loading. It ensures extensibility by allowing custom protocol handling through service provider implementations.

    Example Usage

    
     // Register the factory globally with the URL class
     ServiceLoaderURLStreamHandlerFactory.attach();
     

    How It Works

    1. Loads all available URLStreamHandlerFactory implementations using the service loader mechanism.
    2. Composes them in prioritized order using a CompositeURLStreamHandlerFactory.
    3. Adds a fallback handler for extendable protocols, if any are found.
    4. Delegates creation of stream handlers to this composed factory chain.
    Since:
    1.0.0
    Author:
    Mercy
    See Also:
    URLStreamHandlerFactory, ServiceLoader, CompositeURLStreamHandlerFactory, ExtendableProtocolURLStreamHandler