diff --git a/src/main/java/de/tudresden/inf/mci/brailleplot/util/GeneralResource.java b/src/main/java/de/tudresden/inf/mci/brailleplot/util/GeneralResource.java index d36bce679bd4f5bf17fcc66db8d7430081884e69..7d36ea2d3064ae68c1502058cef33165007f7a16 100644 --- a/src/main/java/de/tudresden/inf/mci/brailleplot/util/GeneralResource.java +++ b/src/main/java/de/tudresden/inf/mci/brailleplot/util/GeneralResource.java @@ -142,7 +142,7 @@ public final class GeneralResource { * @param path Absolute classpath pointing to jar resource. Omit the leading "/". If this point to a resource directory the directory and all contents are exported. * @return A File instance representing the resource on the file system. */ - public static File getOrExportResourceFile(final String path) { + public static synchronized File getOrExportResourceFile(final String path) { if (isRunFromCompiledJar()) { try { JarFile jar = openJarFile(); @@ -179,7 +179,7 @@ public final class GeneralResource { } else { Class cl = getClassRef(); URL resource = cl.getResource("/" + path); // preceding slash for absolute classpath reference - String directoryPath = resource.getPath(); + String directoryPath = UrlHelper.getPathString(resource); return new File(directoryPath); } } diff --git a/src/main/java/de/tudresden/inf/mci/brailleplot/util/UrlHelper.java b/src/main/java/de/tudresden/inf/mci/brailleplot/util/UrlHelper.java new file mode 100644 index 0000000000000000000000000000000000000000..3892978898c7b7c3aa094f9d56886ed876f2921c --- /dev/null +++ b/src/main/java/de/tudresden/inf/mci/brailleplot/util/UrlHelper.java @@ -0,0 +1,25 @@ +package de.tudresden.inf.mci.brailleplot.util; + +import java.net.URL; +import java.net.URLDecoder; +import java.nio.charset.StandardCharsets; + +/** + * This class offers static helper methods for working wth {@link URL} objects. + * @author Georg GraĆnick + * @version 2019.09.27 + */ +public final class UrlHelper { + + private UrlHelper() { } + + /** + * Get the string representation of the path of a {@link URL}. + * For example, spaces are taken care of here. + * @param url The {@link URL} to analyze. + * @return The string representation of the path of the {@link URL}. + */ + public static String getPathString(final URL url) { + return URLDecoder.decode(url.getPath(), StandardCharsets.UTF_8); + } +}