Avoid UnsupportedEncodingException & use const from StandardCharsets (#11948)

Signed-off-by: Christoph Weitkamp <github@christophweitkamp.de>
This commit is contained in:
Christoph Weitkamp
2022-01-03 16:05:08 +01:00
committed by GitHub
parent 3f54327d5a
commit 167f8ebc49
52 changed files with 180 additions and 414 deletions

View File

@@ -13,7 +13,6 @@
package org.openhab.binding.kodi.internal.protocol;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.net.URI;
import java.net.URISyntaxException;
@@ -857,16 +856,11 @@ public class KodiConnection implements KodiClientSocketEventListener {
}
private @Nullable String stripImageUrl(String url) {
try {
// we have to strip ending "/" here because Kodi returns a not valid path and filename
// "fanart":"image://http%3a%2f%2fthetvdb.com%2fbanners%2ffanart%2foriginal%2f263365-31.jpg/"
// "thumbnail":"image://http%3a%2f%2fthetvdb.com%2fbanners%2fepisodes%2f263365%2f5640869.jpg/"
String encodedURL = URLEncoder.encode(stripEnd(url, '/'), StandardCharsets.UTF_8.name());
return imageUri.resolve(encodedURL).toString();
} catch (UnsupportedEncodingException e) {
logger.debug("exception during encoding {}", url, e);
return null;
}
// we have to strip ending "/" here because Kodi returns a not valid path and filename
// "fanart":"image://http%3a%2f%2fthetvdb.com%2fbanners%2ffanart%2foriginal%2f263365-31.jpg/"
// "thumbnail":"image://http%3a%2f%2fthetvdb.com%2fbanners%2fepisodes%2f263365%2f5640869.jpg/"
String encodedURL = URLEncoder.encode(stripEnd(url, '/'), StandardCharsets.UTF_8);
return imageUri.resolve(encodedURL).toString();
}
private String stripEnd(final String str, final char suffix) {