fixed issue with URL stream handler

This commit is contained in:
2022-08-05 15:13:42 +08:00
parent 3f4c5f52e8
commit 40bd8e71bd
7 changed files with 26 additions and 7 deletions

View File

@@ -38,7 +38,7 @@ import java.util.regex.Pattern;
* @since 1.0.0
* @see JarFile#registerUrlProtocolHandler()
*/
public class Handler extends URLStreamHandler {
public abstract class AbstractHandler extends URLStreamHandler {
// NOTE: in order to be found as a URL protocol handler, this class must be public,
// must be named Handler and must be in a package ending '.jar'
@@ -75,11 +75,11 @@ public class Handler extends URLStreamHandler {
private URLStreamHandler fallbackHandler;
public Handler() {
public AbstractHandler() {
this(null);
}
public Handler(JarFile jarFile) {
public AbstractHandler(JarFile jarFile) {
this.jarFile = jarFile;
}

View File

@@ -16,6 +16,8 @@
package net.woggioni.envelope.loader;
import net.woggioni.envelope.loader.jar.Handler;
import java.io.File;
import java.io.FilePermission;
import java.io.IOException;
@@ -60,7 +62,7 @@ public class JarFile extends AbstractJarFile implements Iterable<java.util.jar.J
private static final String PROTOCOL_HANDLER = "java.protocol.handler.pkgs";
private static final String HANDLERS_PACKAGE = "net.woggioni.xclassloader.jar";
private static final String HANDLERS_PACKAGE = "net.woggioni.envelope.loader";
private static final Bytes.AsciiBytes META_INF = new Bytes.AsciiBytes("META-INF/");
@@ -444,7 +446,7 @@ public class JarFile extends AbstractJarFile implements Iterable<java.util.jar.J
* {@link URLStreamHandler} will be located to deal with jar URLs.
*/
public static void registerUrlProtocolHandler() {
Handler.captureJarContextUrl();
AbstractHandler.captureJarContextUrl();
String handlers = System.getProperty(PROTOCOL_HANDLER, "");
System.setProperty(PROTOCOL_HANDLER,
((handlers == null || handlers.isEmpty()) ? HANDLERS_PACKAGE : handlers + "|" + HANDLERS_PACKAGE));

View File

@@ -0,0 +1,15 @@
package net.woggioni.envelope.loader.jar;
import net.woggioni.envelope.loader.AbstractHandler;
import net.woggioni.envelope.loader.JarFile;
public class Handler extends AbstractHandler {
public Handler() {
super();
}
public Handler(JarFile jarFile) {
super(jarFile);
}
}

View File

@@ -2,4 +2,5 @@ module net.woggioni.envelope.loader {
requires java.logging;
requires static lombok;
exports net.woggioni.envelope.loader;
exports net.woggioni.envelope.loader.jar;
}

View File

@@ -2,7 +2,7 @@ package net.woggioni.envelope.loader;
import lombok.SneakyThrows;
import net.woggioni.envelope.loader.JarFile;
import net.woggioni.envelope.loader.Handler;
import net.woggioni.envelope.loader.jar.Handler;
import java.io.File;
import java.io.IOException;