JAL-4001 Changed for Java 8 compatibility
authorBen Soares <b.soares@dundee.ac.uk>
Thu, 15 Jun 2023 19:20:15 +0000 (20:20 +0100)
committerBen Soares <b.soares@dundee.ac.uk>
Thu, 15 Jun 2023 19:20:52 +0000 (20:20 +0100)
src/jalview/analytics/GoogleAnalytics4.java

index d247662..ba8a920 100644 (file)
@@ -2,6 +2,7 @@ package jalview.analytics;
 
 import java.io.IOException;
 import java.io.OutputStream;
+import java.io.UnsupportedEncodingException;
 import java.net.HttpURLConnection;
 import java.net.MalformedURLException;
 import java.net.URL;
@@ -10,6 +11,7 @@ import java.net.URLEncoder;
 import java.nio.charset.StandardCharsets;
 import java.util.AbstractMap;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
@@ -294,10 +296,21 @@ public class GoogleAnalytics4
       {
         sb.append('&');
       }
-      sb.append(URLEncoder.encode(entry.getKey(), StandardCharsets.UTF_8));
+      try
+      {
+        sb.append(URLEncoder.encode(entry.getKey(), "UTF-8"));
+      } catch (UnsupportedEncodingException e)
+      {
+        sb.append(entry.getKey());
+      }
       sb.append('=');
-      sb.append(
-              URLEncoder.encode(entry.getValue(), StandardCharsets.UTF_8));
+      try
+      {
+        sb.append(URLEncoder.encode(entry.getValue(), "UTF-8"));
+      } catch (UnsupportedEncodingException e)
+      {
+        sb.append(entry.getValue());
+      }
     }
     return sb.toString();
   }
@@ -433,7 +446,9 @@ public class GoogleAnalytics4
     }
     if (repeat >= 0 && whitespace != null)
     {
-      sb.append(whitespace.repeat(repeat));
+      // sb.append(whitespace.repeat(repeat));
+      sb.append(String.join("", Collections.nCopies(repeat, whitespace)));
+
     }
     else
     {