Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
12 changes: 2 additions & 10 deletions java-io-base/src/main/java/nbbrd/io/sys/SystemProperties.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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));
}

/**
Expand Down Expand Up @@ -259,12 +259,4 @@ private List<Path> asPaths(String input) {
}
return Collections.emptyList();
}

private URL asURL(String input) {
try {
return input != null ? new URL(input) : null;
} catch (MalformedURLException ex) {
return null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ public void testStringList() {
@Test
public void testURL() throws MalformedURLException {
Formatter<URL> 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
Expand Down
2 changes: 1 addition & 1 deletion java-io-base/src/test/java/nbbrd/io/text/ParserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
14 changes: 7 additions & 7 deletions java-io-base/src/test/java/nbbrd/io/text/TextBuffersTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,20 +128,20 @@ 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) {
return new ByteArrayInputStream(content.getBytes(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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions java-io-curl/src/test/java/nbbrd/io/curl/CurlTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import java.io.IOException;
import java.net.Proxy;
import java.net.URI;
import java.net.URL;
import java.net.URLConnection;

Expand All @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
6 changes: 3 additions & 3 deletions java-io-xml/src/test/java/_test/sample/Person.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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();

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@
<plugin>
<groupId>org.gaul</groupId>
<artifactId>modernizer-maven-plugin</artifactId>
<version>3.4.0</version>
<version>3.5.0</version>
</plugin>
<plugin>
<groupId>de.thetaphi</groupId>
Expand Down
Loading