Avoid UnsupportedEncodingException & use const from StandardCharsets (#11948)
Signed-off-by: Christoph Weitkamp <github@christophweitkamp.de>
This commit is contained in:
committed by
GitHub
parent
3f54327d5a
commit
167f8ebc49
@@ -16,11 +16,11 @@ import static java.util.stream.Collectors.toSet;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
@@ -255,14 +255,7 @@ public class VoiceRSSCloudImpl implements VoiceRSSCloudAPI {
|
||||
* It is in package scope to be accessed by tests.
|
||||
*/
|
||||
private String createURL(String apiKey, String text, String locale, String voice, String audioFormat) {
|
||||
String encodedMsg;
|
||||
try {
|
||||
encodedMsg = URLEncoder.encode(text, "UTF-8");
|
||||
} catch (UnsupportedEncodingException ex) {
|
||||
logger.error("UnsupportedEncodingException for UTF-8 MUST NEVER HAPPEN! Check your JVM configuration!", ex);
|
||||
// fall through and use msg un-encoded
|
||||
encodedMsg = text;
|
||||
}
|
||||
String encodedMsg = URLEncoder.encode(text, StandardCharsets.UTF_8);
|
||||
String url = "http://api.voicerss.org/?key=" + apiKey + "&hl=" + locale + "&c=" + audioFormat;
|
||||
if (!DEFAULT_VOICE.equals(voice)) {
|
||||
url += "&v=" + voice;
|
||||
|
||||
Reference in New Issue
Block a user