temporary commit

This commit is contained in:
2024-12-17 10:03:13 +08:00
parent f28ecca45e
commit 13f7ecc88a
23 changed files with 669 additions and 190 deletions

View File

@@ -0,0 +1,41 @@
package net.woggioni.gbcs.url;
import java.io.IOException;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLStreamHandler;
import java.net.URLStreamHandlerFactory;
public class ClasspathUrlStreamHandlerFactoryProvider implements URLStreamHandlerFactory {
private static class Handler extends URLStreamHandler {
private final ClassLoader classLoader;
public Handler() {
this.classLoader = getClass().getClassLoader();
}
public Handler(ClassLoader classLoader) {
this.classLoader = classLoader;
}
@Override
protected URLConnection openConnection(URL u) throws IOException {
final URL resourceUrl = classLoader.getResource(u.getPath());
return resourceUrl.openConnection();
}
}
@Override
public URLStreamHandler createURLStreamHandler(String protocol) {
URLStreamHandler result;
switch (protocol) {
case "classpath":
result = new Handler();
break;
default:
result = null;
}
return result;
}
}