From 6dead1ee2fc51caee7aa03201c756344509dd092 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Georg=20Gra=C3=9Fnick?=
 <georg.grassnick@mailbox.tu-dresden.de>
Date: Fri, 27 Sep 2019 21:09:20 +0200
Subject: [PATCH] Fix spaces in getOrExportResourceFile()

---
 .../mci/brailleplot/util/GeneralResource.java |  4 +--
 .../inf/mci/brailleplot/util/UrlHelper.java   | 25 +++++++++++++++++++
 2 files changed, 27 insertions(+), 2 deletions(-)
 create mode 100644 src/main/java/de/tudresden/inf/mci/brailleplot/util/UrlHelper.java

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 d36bce67..7d36ea2d 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 00000000..38929788
--- /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);
+    }
+}
-- 
GitLab