added JPMS URL stream handler
All checks were successful
CI / build (push) Successful in 1m41s

This commit is contained in:
2025-01-09 16:13:38 +08:00
parent 8af4a84e49
commit 89817c5624
16 changed files with 176 additions and 11 deletions

View File

@@ -0,0 +1,6 @@
open module net.woggioni.jwo.unit.test {
requires net.woggioni.jwo;
requires net.woggioni.jwo.test.module;
requires org.junit.jupiter.api;
requires static lombok;
}

View File

@@ -0,0 +1,29 @@
package net.woggioni.jwo.test;
import lombok.SneakyThrows;
import net.woggioni.jwo.JWO;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.io.ByteArrayOutputStream;
import java.net.URL;
import java.nio.charset.StandardCharsets;
public class JpmsUrlTest {
@Test
@SneakyThrows
public void test() {
JWO.registerUrlProtocolHandler();
final var module = getClass().getModule();
final var url = new URL("jpms://net.woggioni.jwo.test.module/my/test/resource/file.txt");
System.out.println(module.getName());
System.out.println(url.getHost());
System.out.println(url.getPath());
final var baos = new ByteArrayOutputStream();
try(final var is = url.openConnection().getInputStream()) {
JWO.copy(is, baos);
}
final var content = baos.toString(StandardCharsets.UTF_8);
Assertions.assertEquals("test", content);
}
}