JDK20 URL Constructors deprecated
Deprecated URL constructor:
public URL(URL context, String spec) throws MalformedURLException
The following attempts have been unsuccessful on CentOS 7:
- Original Working Solution (with deprecated URL constructor mentioned above):
- Deprecated API:
url = new URL(context,spec);
- Results with deprecated code:
Case 1:
Context: file:jar:http://myserver/my/jars/my-jar.jar!/mydir/mydir/test_hello.txt, spec=abc.txt Resulting URL: file:jar:http://myserver/my/jars/my-jar.jar!/mydir/mydir/abc.txt
Case 2:
Context: file:ram:my_textfile_original, spec: my.dir.input_test.txt Resulting URL: file:my.dir.input_test.txt
- Deprecated API:
- Unsuccessful Attempt 1:
- New Code:
newURL = new File(context).toURI().resolve(spec).toURL();
- Results with new code:
Case 1:
Context: file:jar:http://myserver/my/jars/my-jar.jar!/mydir/mydir/test_hello.txt, spec=abc.txt Resulting URL: file:/home/user/my/homedir/otherdir/file:jar:http:/myserver/my/jars/my-jar.jar!/mydir/mydir/abc.txt
Case 2:
Context: file:ram:my_textfile_original, spec: my.dir.input_test.txt Resulting URL: file:/home/user/my/homedir/otherdir/my.dir.input_test.txt
- New Code:
- Unsuccessful Attempt 2:
New Code:
Path myPath = Paths.get(context,spec); URI newURI = new URL(myPath.toString()); url = newURI.toURL();
Results with new code:
Case 1:
Context: file:jar:http://myserver/my/jars/my-jar.jar!/mydir/mydir/test_hello.txt, spec=abc.txt Resulting URL: file:jar:http:/myserver/my/jars/my-jar.jar!/mydir/mydir/abc.txt
Case 2:
Context: file:ram:my_textfile_original, spec: my.dir.input_test.txt Resulting URL: file:ram:my_textfile_original/my.dir.input_test.txt