Package io.microsphere.net
Class MutableURLStreamHandlerFactory<H extends java.net.URLStreamHandler>
- java.lang.Object
-
- io.microsphere.net.MutableURLStreamHandlerFactory<H>
-
- Type Parameters:
H
- The type ofURLStreamHandler
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 ofURLStreamHandlerFactory
that allows dynamic registration and retrieval ofURLStreamHandler
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 Summary
Constructors Constructor Description MutableURLStreamHandlerFactory()
Constructs a new instanceMutableURLStreamHandlerFactory(java.util.Map<java.lang.String,H> handlers)
Constructs a new instance with the specified handlers
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description MutableURLStreamHandlerFactory
addURLStreamHandler(java.lang.String protocol, H handler)
Adds a new handler for the specified protocolMutableURLStreamHandlerFactory<H>
clearHandlers()
Clears all handlersjava.net.URLStreamHandler
createURLStreamHandler(java.lang.String protocol)
java.util.Collection<H>
getHandlers()
Retrieves all handlersH
getURLStreamHandler(java.lang.String protocol)
Retrieves the handler for the specified protocolH
removeURLStreamHandler(java.lang.String protocol)
Removes the handler for the specified protocol
-
-
-
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 protocolhandler
- 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 interfacejava.net.URLStreamHandlerFactory
-
clearHandlers
public MutableURLStreamHandlerFactory<H> clearHandlers()
Clears all handlers- Returns:
- this instance
-
-