Skip to content

io microsphere net DelegatingURLStreamHandlerFactory

github-actions[bot] edited this page Mar 21, 2026 · 1 revision

DelegatingURLStreamHandlerFactory

Type: Class | Module: microsphere-java-core | Package: io.microsphere.net | Since: 1.0.0

Source: microsphere-java-core/src/main/java/io/microsphere/net/DelegatingURLStreamHandlerFactory.java

Overview

A delegating implementation of URLStreamHandlerFactory 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.

Declaration

public class DelegatingURLStreamHandlerFactory implements URLStreamHandlerFactory

Author: Mercy

Version Information

  • Introduced in: 1.0.0
  • Current Project Version: 0.1.10-SNAPSHOT

Version Compatibility

This component is tested and compatible with the following Java versions:

Java Version Status
Java 8 ✅ Compatible
Java 11 ✅ Compatible
Java 17 ✅ Compatible
Java 21 ✅ Compatible
Java 25 ✅ Compatible

Examples

// 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);

Usage

Maven Dependency

Add the following dependency to your pom.xml:

<dependency>
    <groupId>io.github.microsphere-projects</groupId>
    <artifactId>microsphere-java-core</artifactId>
    <version>${microsphere-java.version}</version>
</dependency>

Tip: Use the BOM (microsphere-java-dependencies) for consistent version management. See the Getting Started guide.

Import

import io.microsphere.net.DelegatingURLStreamHandlerFactory;

API Reference

Public Methods

Method Description
createURLStreamHandler

This documentation was auto-generated from the source code of microsphere-java.

Home

java-annotations

java-core

jdk-tools

lang-model

annotation-processor

java-test

Clone this wiki locally