Replace usage of deprecated java.net.URL constructor with URI (#12755)

This commit replaces the usage of the deprecated java.net.URL constructor with URI, later converting toURL where necessary to interoperate with the URLConnection API.
This commit is contained in:
Chris Hegarty 2023-11-03 20:02:22 +00:00 committed by GitHub
parent a35573eed9
commit 5ef651fc4c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 11 deletions

View File

@ -21,6 +21,7 @@ import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.OutputStreamWriter; import java.io.OutputStreamWriter;
import java.io.Writer; import java.io.Writer;
import java.net.URI;
import java.net.URL; import java.net.URL;
import java.net.URLConnection; import java.net.URLConnection;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
@ -111,7 +112,7 @@ public class GenerateJflexTLDMacros {
public GenerateJflexTLDMacros(String tldFileURL, String jflexFile, String tldListFile) public GenerateJflexTLDMacros(String tldFileURL, String jflexFile, String tldListFile)
throws Exception { throws Exception {
this.tldFileURL = new URL(tldFileURL); this.tldFileURL = URI.create(tldFileURL).toURL();
this.jflexMacroFile = Paths.get(jflexFile); this.jflexMacroFile = Paths.get(jflexFile);
this.tldListFile = Paths.get(tldListFile); this.tldListFile = Paths.get(tldListFile);
} }

View File

@ -27,6 +27,7 @@ import java.io.InputStreamReader;
import java.io.OutputStream; import java.io.OutputStream;
import java.io.OutputStreamWriter; import java.io.OutputStreamWriter;
import java.io.Writer; import java.io.Writer;
import java.net.URI;
import java.net.URL; import java.net.URL;
import java.net.URLConnection; import java.net.URLConnection;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
@ -155,19 +156,19 @@ public class GenerateUTR30DataFiles {
} }
private static void getNFKCDataFilesFromIcuProject(String releaseTag) throws IOException { private static void getNFKCDataFilesFromIcuProject(String releaseTag) throws IOException {
URL icuTagsURL = new URL(ICU_GIT_TAG_URL + "/"); URI icuTagsURI = URI.create(ICU_GIT_TAG_URL + "/");
URL icuReleaseTagURL = new URL(icuTagsURL, releaseTag + "/"); URI icuReleaseTagURI = icuTagsURI.resolve(releaseTag + "/");
URL norm2url = new URL(icuReleaseTagURL, ICU_DATA_NORM2_PATH + "/"); URI norm2uri = icuReleaseTagURI.resolve(ICU_DATA_NORM2_PATH + "/");
System.err.print("Downloading " + NFKC_TXT + " ... "); System.err.print("Downloading " + NFKC_TXT + " ... ");
download(new URL(norm2url, NFKC_TXT), NFKC_TXT); download(norm2uri.resolve(NFKC_TXT), NFKC_TXT);
System.err.println("done."); System.err.println("done.");
System.err.print("Downloading " + NFKC_CF_TXT + " ... "); System.err.print("Downloading " + NFKC_CF_TXT + " ... ");
download(new URL(norm2url, NFKC_CF_TXT), NFKC_CF_TXT); download(norm2uri.resolve(NFKC_CF_TXT), NFKC_CF_TXT);
System.err.println("done."); System.err.println("done.");
System.err.print("Downloading " + NFKC_CF_TXT + " and making diacritic rules one-way ... "); System.err.print("Downloading " + NFKC_CF_TXT + " and making diacritic rules one-way ... ");
URLConnection connection = openConnection(new URL(norm2url, NFC_TXT)); URLConnection connection = openConnection(norm2uri.resolve(NFC_TXT).toURL());
try (BufferedReader reader = try (BufferedReader reader =
new BufferedReader( new BufferedReader(
new InputStreamReader(connection.getInputStream(), StandardCharsets.UTF_8)); new InputStreamReader(connection.getInputStream(), StandardCharsets.UTF_8));
@ -210,8 +211,8 @@ public class GenerateUTR30DataFiles {
System.err.println("done."); System.err.println("done.");
} }
private static void download(URL url, String outputFile) throws IOException { private static void download(URI uri, String outputFile) throws IOException {
final URLConnection connection = openConnection(url); final URLConnection connection = openConnection(uri.toURL());
try (InputStream inputStream = connection.getInputStream(); try (InputStream inputStream = connection.getInputStream();
OutputStream outputStream = Files.newOutputStream(Path.of(outputFile))) { OutputStream outputStream = Files.newOutputStream(Path.of(outputFile))) {
inputStream.transferTo(outputStream); inputStream.transferTo(outputStream);

View File

@ -23,6 +23,7 @@ import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent; import java.awt.event.MouseEvent;
import java.io.IOException; import java.io.IOException;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.net.URL; import java.net.URL;
import javax.swing.JLabel; import javax.swing.JLabel;
@ -37,8 +38,8 @@ public final class URLLabel extends JLabel {
super(text); super(text);
try { try {
this.link = new URL(text); this.link = (new URI(text)).toURL();
} catch (MalformedURLException e) { } catch (URISyntaxException | MalformedURLException e) {
throw new LukeException(e.getMessage(), e); throw new LukeException(e.getMessage(), e);
} }