Class MutableURLStreamHandlerFactory<H extends java.net.URLStreamHandler>

  • Type Parameters:
    H - The type of URLStreamHandler or subtype thereof
    All Implemented Interfaces:
    java.net.URLStreamHandlerFactory

    public class MutableURLStreamHandlerFactory<H extends java.net.URLStreamHandler>
    extends java.lang.Object
    implements java.net.URLStreamHandlerFactory
    A mutable and non-thread-safe implementation of URLStreamHandlerFactory that allows dynamic registration and retrieval of URLStreamHandler instances for specific protocols.

    This class provides methods to add, remove, and retrieve URL stream handlers dynamically at runtime, making it suitable for environments where protocol handling needs to be modified or extended programmatically.

    Example Usage

    
     MutableURLStreamHandlerFactory factory = new MutableURLStreamHandlerFactory();
    
     // Add a custom handler for the "myproto" protocol
     factory.addURLStreamHandler("myproto", new MyCustomURLStreamHandler());
    
     // Retrieve a registered handler
     URLStreamHandler handler = factory.getURLStreamHandler("myproto");
    
     // Remove a handler
     factory.removeURLStreamHandler("myproto");
    
     // Clear all handlers
     factory.clearHandlers();
     

    Note: This class is not thread-safe. Concurrent access from multiple threads should be externally synchronized.

    Since:
    1.0.0
    Author:
    Mercy
    See Also:
    URLStreamHandlerFactory, URLStreamHandler
    • Constructor Detail

      • MutableURLStreamHandlerFactory

        public MutableURLStreamHandlerFactory()
        Constructs a new instance
      • MutableURLStreamHandlerFactory

        public MutableURLStreamHandlerFactory​(java.util.Map<java.lang.String,​H> handlers)
        Constructs a new instance with the specified handlers
        Parameters:
        handlers - the handlers
    • Method Detail

      • addURLStreamHandler

        public MutableURLStreamHandlerFactory addURLStreamHandler​(java.lang.String protocol,
                                                                  H handler)
        Adds a new handler for the specified protocol
        Parameters:
        protocol - the protocol
        handler - the handler
        Returns:
        this instance
      • removeURLStreamHandler

        public H removeURLStreamHandler​(java.lang.String protocol)
        Removes the handler for the specified protocol
        Parameters:
        protocol - the protocol
        Returns:
        the removed handler
      • getURLStreamHandler

        public H getURLStreamHandler​(java.lang.String protocol)
        Retrieves the handler for the specified protocol
        Parameters:
        protocol - the protocol
        Returns:
        the handler
      • getHandlers

        public java.util.Collection<H> getHandlers()
        Retrieves all handlers
        Returns:
        the handlers
      • createURLStreamHandler

        public java.net.URLStreamHandler createURLStreamHandler​(java.lang.String protocol)
        Specified by:
        createURLStreamHandler in interface java.net.URLStreamHandlerFactory