Unverified Commit e29ff300 authored by luvarqpp's avatar luvarqpp Committed by GitHub
Browse files

Remove unnesesary runtime charset search (#897)

Use StandardCharsets.UTF_8 instead of "UTF-8" string. This removes necessity to throw a checked exception.
parent 98c4b996
package org.gitlab4j.api.utils; package org.gitlab4j.api.utils;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import org.gitlab4j.api.GitLabApiException;
public class UrlEncoder { public class UrlEncoder {
...@@ -11,21 +10,16 @@ public class UrlEncoder { ...@@ -11,21 +10,16 @@ public class UrlEncoder {
* *
* @param s the String to URL encode * @param s the String to URL encode
* @return the URL encoded strings * @return the URL encoded strings
* @throws GitLabApiException if any exception occurs
*/ */
public static String urlEncode(String s) throws GitLabApiException { public static String urlEncode(String s) {
try { String encoded = URLEncoder.encode(s, StandardCharsets.UTF_8);
String encoded = URLEncoder.encode(s, "UTF-8"); // Since the encode method encodes plus signs as %2B,
// Since the encode method encodes plus signs as %2B, // we can simply replace the encoded spaces with the correct encoding here
// we can simply replace the encoded spaces with the correct encoding here encoded = encoded.replace("+", "%20");
encoded = encoded.replace("+", "%20"); encoded = encoded.replace(".", "%2E");
encoded = encoded.replace(".", "%2E"); encoded = encoded.replace("-", "%2D");
encoded = encoded.replace("-", "%2D"); encoded = encoded.replace("_", "%5F");
encoded = encoded.replace("_", "%5F"); return (encoded);
return (encoded);
} catch (Exception e) {
throw new GitLabApiException(e);
}
} }
} }
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment