From fd3eea985804e06f67b583eb3cf01eb60d7ffe9a Mon Sep 17 00:00:00 2001 From: joe Date: Tue, 13 Jun 2023 03:55:36 +0900 Subject: [PATCH] Properly Decode URL Properly decode url in getLibPath method incase processing library is in non ascii named folder. Code taken straight from this stack overflow answer https://stackoverflow.com/questions/6138127/how-to-do-url-decoding-in-java --- src/gab/opencv/OpenCV.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/gab/opencv/OpenCV.java b/src/gab/opencv/OpenCV.java index d3dfd6b..693de3c 100644 --- a/src/gab/opencv/OpenCV.java +++ b/src/gab/opencv/OpenCV.java @@ -41,6 +41,7 @@ import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.nio.IntBuffer; +import java.nio.charset.StandardCharsets; import java.io.File; import java.lang.reflect.Field; import java.net.URL; @@ -367,9 +368,14 @@ private void setupWorkingImages(){ private String getLibPath() { URL url = this.getClass().getResource("OpenCV.class"); if (url != null) { - // Convert URL to string, taking care of spaces represented by the "%20" - // string. - String path = url.toString().replace("%20", " "); + String path = ""; + try{ + path = java.net.URLDecoder.decode(url.toString(), StandardCharsets.UTF_8.name()); + } + catch(Exception e){ + //not going to happen - value came from JDK's own StandardCharsets + e.printStackTrace(); + } int n0 = path.indexOf('/'); int n1 = -1;