Package io.microsphere.net
Class DelegatingURLStreamHandlerFactory
- java.lang.Object
-
- io.microsphere.net.DelegatingURLStreamHandlerFactory
-
- All Implemented Interfaces:
java.net.URLStreamHandlerFactory
- Direct Known Subclasses:
ServiceLoaderURLStreamHandlerFactory
public class DelegatingURLStreamHandlerFactory extends java.lang.Object implements java.net.URLStreamHandlerFactoryA delegating implementation ofURLStreamHandlerFactorythat forwards all calls to a provided delegate factory.This class is useful when you want to wrap or modify the behavior of an existing
URLStreamHandlerFactoryinstance, such as adding custom logic before or after delegation, without directly modifying its implementation.Example Usage
// Create a custom URLStreamHandlerFactory URLStreamHandlerFactory customFactory = protocol -> { if ("http".equals(protocol)) { return new MyCustomHttpURLStreamHandler(); } return null; }; // Wrap it with DelegatingURLStreamHandlerFactory DelegatingURLStreamHandlerFactory delegatingFactory = new DelegatingURLStreamHandlerFactory(customFactory); // Set the delegating factory as the default URL.setURLStreamHandlerFactory(delegatingFactory);In this example, any request for a URL handler will first go through the
DelegatingURLStreamHandlerFactory, which in turn delegates the handling to the wrapped custom factory.- Since:
- 1.0.0
- Author:
- Mercy
-
-
Constructor Summary
Constructors Constructor Description DelegatingURLStreamHandlerFactory(java.net.URLStreamHandlerFactory delegate)Constructs a new instance with the specified delegate factory.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.net.URLStreamHandlercreateURLStreamHandler(java.lang.String protocol)protected java.net.URLStreamHandlerFactorygetDelegate()Get the delegate ofURLStreamHandlerFactory
-
-
-
Constructor Detail
-
DelegatingURLStreamHandlerFactory
public DelegatingURLStreamHandlerFactory(java.net.URLStreamHandlerFactory delegate)
Constructs a new instance with the specified delegate factory.- Parameters:
delegate- the delegate factory to which calls will be forwarded, must not benull- Throws:
java.lang.IllegalArgumentException- if the provided delegate isnull
-
-
Method Detail
-
createURLStreamHandler
public java.net.URLStreamHandler createURLStreamHandler(java.lang.String protocol)
- Specified by:
createURLStreamHandlerin interfacejava.net.URLStreamHandlerFactory
-
getDelegate
protected final java.net.URLStreamHandlerFactory getDelegate()
Get the delegate ofURLStreamHandlerFactory- Returns:
- non-null
-
-