Skip to content

io microsphere net SubProtocolURLConnectionFactory

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

SubProtocolURLConnectionFactory

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

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

Overview

A factory for creating URLConnection instances that handle sub-protocols.

Implementations of this interface are responsible for determining whether they can handle a specific URL and its associated sub-protocols, and for creating the appropriate connection if possible.

Example Usage

{@code
public class MySubProtocolURLConnectionFactory implements SubProtocolURLConnectionFactory {

### Declaration

```java
public interface SubProtocolURLConnectionFactory
```

**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

### Example 1

```java
public class MySubProtocolURLConnectionFactory implements SubProtocolURLConnectionFactory {
    @Override
    public boolean supports(URL url, List subProtocols) {
        // Check if the URL and sub-protocols are supported
        return url.getProtocol().equals("http") && subProtocols.contains("myprotocol");
    }

    @Override
    public URLConnection create(URL url, List subProtocols, Proxy proxy) throws IOException {
        // Create and return a custom URLConnection
        return new MyCustomURLConnection(url, proxy);
    }
}
```

### Example 2

```java
URL.setURLStreamHandlerFactory(handler -> {
    if (handler.equals("http")) {
        return new MyURLStreamHandler();
    }
    return null;
});
```

## Usage

### Maven Dependency

Add the following dependency to your `pom.xml`:

```xml

    io.github.microsphere-projects
    microsphere-java-core
    ${microsphere-java.version}

```

> **Tip:** Use the BOM (`microsphere-java-dependencies`) for consistent version management. See the [Getting Started](https://github.com/microsphere-projects/microsphere-java#getting-started) guide.

### Import

```java
import io.microsphere.net.SubProtocolURLConnectionFactory;
```

---

*This documentation was auto-generated from the source code of [microsphere-java](https://github.com/microsphere-projects/microsphere-java).*

Home

java-annotations

java-core

jdk-tools

lang-model

annotation-processor

java-test

Clone this wiki locally