diff --git a/java-io-base/src/main/java/internal/io/text/InternalParser.java b/java-io-base/src/main/java/internal/io/text/InternalParser.java index 80871446..07ee609a 100644 --- a/java-io-base/src/main/java/internal/io/text/InternalParser.java +++ b/java-io-base/src/main/java/internal/io/text/InternalParser.java @@ -303,8 +303,8 @@ private boolean isLocaleSeparator(char c) { public URL parseURL(CharSequence input) { if (input != null) { try { - return new URL(input.toString()); - } catch (MalformedURLException ex) { + return new URI(input.toString()).toURL(); + } catch (MalformedURLException | URISyntaxException ex) { doNothing(ex); } } diff --git a/java-io-base/src/main/java/nbbrd/io/sys/SystemProperties.java b/java-io-base/src/main/java/nbbrd/io/sys/SystemProperties.java index 99f959dd..a4472837 100644 --- a/java-io-base/src/main/java/nbbrd/io/sys/SystemProperties.java +++ b/java-io-base/src/main/java/nbbrd/io/sys/SystemProperties.java @@ -1,9 +1,9 @@ package nbbrd.io.sys; +import internal.io.text.InternalParser; import lombok.NonNull; import org.jspecify.annotations.Nullable; -import java.net.MalformedURLException; import java.net.URL; import java.nio.file.FileSystem; import java.nio.file.FileSystems; @@ -108,7 +108,7 @@ public final class SystemProperties { * @return */ public @Nullable URL getJavaVendorUrl() { - return asURL(get(JAVA_VENDOR_URL)); + return InternalParser.parseURL(get(JAVA_VENDOR_URL)); } /** @@ -259,12 +259,4 @@ private List asPaths(String input) { } return Collections.emptyList(); } - - private URL asURL(String input) { - try { - return input != null ? new URL(input) : null; - } catch (MalformedURLException ex) { - return null; - } - } } diff --git a/java-io-base/src/test/java/nbbrd/io/text/FormatterTest.java b/java-io-base/src/test/java/nbbrd/io/text/FormatterTest.java index efb56820..ae707b94 100644 --- a/java-io-base/src/test/java/nbbrd/io/text/FormatterTest.java +++ b/java-io-base/src/test/java/nbbrd/io/text/FormatterTest.java @@ -213,7 +213,7 @@ public void testStringList() { @Test public void testURL() throws MalformedURLException { Formatter f = onURL(); - assertCompliance(f, new URL("file:/C:/temp/x.xml"), "file:/C:/temp/x.xml"); + assertCompliance(f, URI.create("file:/C:/temp/x.xml").toURL(), "file:/C:/temp/x.xml"); } @Test diff --git a/java-io-base/src/test/java/nbbrd/io/text/ParserTest.java b/java-io-base/src/test/java/nbbrd/io/text/ParserTest.java index a924ce4e..09d573db 100644 --- a/java-io-base/src/test/java/nbbrd/io/text/ParserTest.java +++ b/java-io-base/src/test/java/nbbrd/io/text/ParserTest.java @@ -251,7 +251,7 @@ public void testOnURL() throws MalformedURLException { assertCompliance(onURL(), "file:/C:/temp/x.xml"); assertThat(onURL().parse("file:/C:/temp/x.xml")) - .isEqualTo(new URL("file:/C:/temp/x.xml")); + .isEqualTo(URI.create("file:/C:/temp/x.xml").toURL()); assertThat(onURL().parse(":/C:/temp/x.xml")) .isNull(); diff --git a/java-io-base/src/test/java/nbbrd/io/text/TextBuffersTest.java b/java-io-base/src/test/java/nbbrd/io/text/TextBuffersTest.java index d2df267d..689f8c41 100644 --- a/java-io-base/src/test/java/nbbrd/io/text/TextBuffersTest.java +++ b/java-io-base/src/test/java/nbbrd/io/text/TextBuffersTest.java @@ -128,10 +128,10 @@ public void testOutput() throws IOException { private static final int DEFAULT_BLOCK_BUFFER_SIZE = (int) BlockSizer.DEFAULT_BLOCK_BUFFER_SIZE; private static Path newInputFile(String content, Charset charset) throws IOException { - File result = File.createTempFile("input", ".csv"); - result.deleteOnExit(); - Files.write(result.toPath(), content.getBytes(charset)); - return result.toPath(); + Path result = Files.createTempFile("input", ".csv"); + result.toFile().deleteOnExit(); + Files.write(result, content.getBytes(charset)); + return result; } private static InputStream newInputStream(String content, Charset charset) { @@ -139,9 +139,9 @@ private static InputStream newInputStream(String content, Charset charset) { } private static Path newOutputFile() throws IOException { - File temp = File.createTempFile("output", ".csv"); - temp.deleteOnExit(); - return temp.toPath(); + Path result = Files.createTempFile("output", ".csv"); + result.toFile().deleteOnExit(); + return result; } private static OutputStream newOutputStream() { diff --git a/java-io-curl/src/test/java/nbbrd/io/curl/CurlHttpURLConnectionTest.java b/java-io-curl/src/test/java/nbbrd/io/curl/CurlHttpURLConnectionTest.java index 6cbdbdfd..80189ca7 100644 --- a/java-io-curl/src/test/java/nbbrd/io/curl/CurlHttpURLConnectionTest.java +++ b/java-io-curl/src/test/java/nbbrd/io/curl/CurlHttpURLConnectionTest.java @@ -362,7 +362,7 @@ public void testReadTimeout(@TempDir File temp) throws IOException { @Test public void testInvalidHost(@TempDir File temp) throws IOException { - HttpURLConnection x = curl(new URL("http://localhoooooost"), temp); + HttpURLConnection x = curl(URI.create("http://localhoooooost").toURL(), temp); assertThatIOException() .isThrownBy(x::connect) @@ -374,7 +374,7 @@ private URL wireURL(String path) throws MalformedURLException { if (!path.startsWith("/")) { path = "/" + path; } - return new URL(String.format(Locale.ROOT, "%s%s", wire.baseUrl(), path)); + return URI.create(String.format(Locale.ROOT, "%s%s", wire.baseUrl(), path)).toURL(); } private CurlHttpURLConnection curl(URL url, File temp) { diff --git a/java-io-curl/src/test/java/nbbrd/io/curl/CurlTest.java b/java-io-curl/src/test/java/nbbrd/io/curl/CurlTest.java index 650e281e..951cc493 100644 --- a/java-io-curl/src/test/java/nbbrd/io/curl/CurlTest.java +++ b/java-io-curl/src/test/java/nbbrd/io/curl/CurlTest.java @@ -11,7 +11,7 @@ import java.net.InetSocketAddress; import java.net.MalformedURLException; import java.net.Proxy; -import java.net.URL; +import java.net.URI; import java.nio.charset.Charset; import java.nio.file.Path; import java.util.List; @@ -36,7 +36,7 @@ public void testCommandBuilder(@TempDir Path temp) throws MalformedURLException assertThat(new Curl.CommandBuilder().request("POST").build()) .containsExactly("curl", "-X", "POST"); - assertThat(new Curl.CommandBuilder().url(new URL("https://www.nbb.be")).build()) + assertThat(new Curl.CommandBuilder().url(URI.create("https://www.nbb.be").toURL()).build()) .containsExactly("curl", "https://www.nbb.be"); assertThat(new Curl.CommandBuilder().proxy(Proxy.NO_PROXY).build()) diff --git a/java-io-http/src/test/java/nbbrd/io/http/UrlConnectionFactoryTest.java b/java-io-http/src/test/java/nbbrd/io/http/UrlConnectionFactoryTest.java index 533eccce..5633a3e5 100644 --- a/java-io-http/src/test/java/nbbrd/io/http/UrlConnectionFactoryTest.java +++ b/java-io-http/src/test/java/nbbrd/io/http/UrlConnectionFactoryTest.java @@ -4,6 +4,7 @@ import java.io.IOException; import java.net.Proxy; +import java.net.URI; import java.net.URL; import java.net.URLConnection; @@ -14,7 +15,7 @@ public class UrlConnectionFactoryTest { @Test public void testGetDefault() throws IOException { UrlConnectionFactory x = UrlConnectionFactory.getDefault(); - URL url = new URL("http://localhost"); + URL url = URI.create("http://localhost").toURL(); URLConnection connection = x.openConnection(url, Proxy.NO_PROXY); diff --git a/java-io-http/src/test/java/nbbrd/io/http/UrlHelperTest.java b/java-io-http/src/test/java/nbbrd/io/http/UrlHelperTest.java index e9ca12ae..b57bf9e0 100644 --- a/java-io-http/src/test/java/nbbrd/io/http/UrlHelperTest.java +++ b/java-io-http/src/test/java/nbbrd/io/http/UrlHelperTest.java @@ -23,7 +23,7 @@ public void testProtocolHelpers() throws MalformedURLException { @Test public void testToURIAndToURLRoundTrip() throws IOException { - URL url = new URL("http://localhost/path?q=v"); + URL url = URI.create("http://localhost/path?q=v").toURL(); URI uri = UrlConnectionHttpClient.toURI(url); diff --git a/java-io-xml/src/test/java/_test/sample/Person.java b/java-io-xml/src/test/java/_test/sample/Person.java index 20901d37..331d9839 100644 --- a/java-io-xml/src/test/java/_test/sample/Person.java +++ b/java-io-xml/src/test/java/_test/sample/Person.java @@ -93,7 +93,7 @@ public static String getString(Charset encoding, boolean formatted) { for (Charset encoding : ENCODINGS) { marshaller.setProperty(Marshaller.JAXB_ENCODING, encoding.name()); - File encodedFile = File.createTempFile("person_" + encoding.name() + "_", ".xml"); + File encodedFile = Files.createTempFile("person_" + encoding.name() + "_", ".xml").toFile(); encodedFile.deleteOnExit(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, false); marshaller.marshal(JOHN_DOE, encodedFile); @@ -112,13 +112,13 @@ public static String getString(Charset encoding, boolean formatted) { } } - FILE_EMPTY = File.createTempFile("empty_", ".xml"); + FILE_EMPTY = Files.createTempFile("empty_", ".xml").toFile(); FILE_EMPTY.deleteOnExit(); PATH_EMPTY = FILE_EMPTY.toPath(); CHARS_EMPTY = ""; - FILE_MISSING = File.createTempFile("missing_", ".xml"); + FILE_MISSING = Files.createTempFile("missing_", ".xml").toFile(); FILE_MISSING.delete(); PATH_MISSING = FILE_MISSING.toPath(); diff --git a/pom.xml b/pom.xml index 2cb8950c..1849ad76 100644 --- a/pom.xml +++ b/pom.xml @@ -173,7 +173,7 @@ org.gaul modernizer-maven-plugin - 3.4.0 + 3.5.0 de.thetaphi