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.URLStreamHandlerFactory
A delegating implementation ofURLStreamHandlerFactory
that forwards all calls to a provided delegate factory.This class is useful when you want to wrap or modify the behavior of an existing
URLStreamHandlerFactory
instance, 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.URLStreamHandler
createURLStreamHandler(java.lang.String protocol)
protected java.net.URLStreamHandlerFactory
getDelegate()
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:
createURLStreamHandler
in interfacejava.net.URLStreamHandlerFactory
-
getDelegate
protected final java.net.URLStreamHandlerFactory getDelegate()
Get the delegate ofURLStreamHandlerFactory
- Returns:
- non-null
-
-