From: Ben Soares Date: Thu, 15 Jun 2023 19:20:15 +0000 (+0100) Subject: JAL-4001 Changed for Java 8 compatibility X-Git-Tag: Release_2_11_4_0~264 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=d27e73b6519abfe5922ae716efe9a8dcc58c7751;p=jalview.git JAL-4001 Changed for Java 8 compatibility --- diff --git a/src/jalview/analytics/GoogleAnalytics4.java b/src/jalview/analytics/GoogleAnalytics4.java index d247662..ba8a920 100644 --- a/src/jalview/analytics/GoogleAnalytics4.java +++ b/src/jalview/analytics/GoogleAnalytics4.java @@ -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 {