Skip to content

Commit

Permalink
Change URL to URI
Browse files Browse the repository at this point in the history
URL is deprecated
  • Loading branch information
Antoniafriedrich committed Nov 7, 2024
1 parent d33bbb1 commit 5299234
Show file tree
Hide file tree
Showing 9 changed files with 112 additions and 107 deletions.
20 changes: 13 additions & 7 deletions src/main/java/de/urmel_dl/dbt/common/DBTVersion.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.UncheckedIOException;
import java.net.URL;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Locale;
import java.util.Map;
import java.util.Properties;
Expand Down Expand Up @@ -55,25 +56,30 @@ public static String getVersion() {

private static Properties loadVersionProperties() {
Properties props = new Properties();
URL gitPropURL = MIRCoreVersion.class.getResource("/de/urmel_dl/dbt/git.properties");
try (InputStream gitPropStream = getInputStream(gitPropURL);) {
URI gitPropURI;
try {
gitPropURI = MIRCoreVersion.class.getResource("/de/urmel_dl/dbt/git.properties").toURI();
} catch (URISyntaxException e) {
throw new RuntimeException(e);
}
try (InputStream gitPropStream = getInputStream(gitPropURI);) {
props.load(gitPropStream);
} catch (IOException e) {
throw new UncheckedIOException("Error while initializing DBTVersion.", e);
}
return props;
}

private static InputStream getInputStream(URL gitPropURL) throws IOException {
if (gitPropURL == null) {
private static InputStream getInputStream(URI gitPropURI) throws IOException {
if (gitPropURI == null) {
return new InputStream() {
@Override
public int read() throws IOException {
public int read() {
return -1;
}
};
}
return gitPropURL.openStream();
return gitPropURI.toURL().openStream();
}

public static String getBranch() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,8 @@

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLDecoder;
import java.nio.file.Files;
import java.util.Arrays;
Expand Down Expand Up @@ -109,7 +107,7 @@ private boolean validateReferrer(final HttpServletRequest httpServletRequest) {
return false;
}
try {
final String pathInfo = new URL(referrer).getPath();
final String pathInfo = URI.create(referrer).getPath();
if (PATTERN_ALLOWED_REFERRER.matcher(pathInfo).matches()) {
Optional<String> optDerId = Arrays.stream(pathInfo.split("/"))
.filter(f -> PATTERN_DERIVATE_ID.matcher(f).matches())
Expand All @@ -122,7 +120,7 @@ private boolean validateReferrer(final HttpServletRequest httpServletRequest) {
return Files.exists(MCRPath.getPath(derivateId, fileName));
}
}
} catch (MalformedURLException | UnsupportedEncodingException e) {
} catch (UnsupportedEncodingException e) {
LOGGER.error("Couldn't parse referrer " + referrer + ".", e);
}
return false;
Expand Down
6 changes: 2 additions & 4 deletions src/main/java/de/urmel_dl/dbt/media/MediaService.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import java.io.UncheckedIOException;
import java.math.BigInteger;
import java.net.URI;
import java.net.URL;
import java.nio.channels.Channels;
import java.nio.channels.ReadableByteChannel;
import java.nio.charset.StandardCharsets;
Expand Down Expand Up @@ -506,10 +505,9 @@ public void run() {

Path tmpFile = Files.createTempDirectory("media").resolve(job.getId() + ".zip");
try {
URL website = new URL(SERVER_ADDRESS + new MessageFormat(CONVERTER_DOWNLOAD_PATH, Locale.ROOT)
URI website = URI.create(SERVER_ADDRESS + new MessageFormat(CONVERTER_DOWNLOAD_PATH, Locale.ROOT)
.format(new Object[] { job.getId().replaceAll(" ", "%20") }));
ReadableByteChannel rbc = Channels.newChannel(website.openStream());

ReadableByteChannel rbc = Channels.newChannel(website.toURL().openStream());
try (FileOutputStream fos = new FileOutputStream(tmpFile.toFile())) {
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.net.URI;
import java.nio.file.Files;
import java.nio.file.NoSuchFileException;
import java.nio.file.Path;
Expand Down Expand Up @@ -63,7 +63,8 @@ public class MigrationCommands extends MCRAbstractCommands {
@MCRCommand(syntax = "fix objects for base {0} with file {1}",
help = "transforms all mycore objects for base {0} with the given file or URL {1}")
public static List<String> xsltObjects(final String base, final String xslFile) throws Exception {
URL styleFile = MigrationCommands.class.getResource("/xsl/" + xslFile);
URI styleFile = MigrationCommands.class.getResource("/xsl/" + xslFile).toURI();

if (styleFile == null) {
final File file = new File(xslFile);

Expand All @@ -72,7 +73,7 @@ public static List<String> xsltObjects(final String base, final String xslFile)
return null;
}

styleFile = file.toURI().toURL();
styleFile = file.toURI();
}

List<String> cmds = new ArrayList<String>();
Expand Down
Loading

0 comments on commit 5299234

Please sign in to comment.