Skip to content

Commit e29ff30

Browse files
authored
Remove unnesesary runtime charset search (#897)
Use StandardCharsets.UTF_8 instead of "UTF-8" string. This removes necessity to throw a checked exception.
1 parent 98c4b99 commit e29ff30

File tree

1 file changed

+11
-17
lines changed

1 file changed

+11
-17
lines changed
Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
package org.gitlab4j.api.utils;
22

33
import java.net.URLEncoder;
4-
5-
import org.gitlab4j.api.GitLabApiException;
4+
import java.nio.charset.StandardCharsets;
65

76
public class UrlEncoder {
87

@@ -11,21 +10,16 @@ public class UrlEncoder {
1110
*
1211
* @param s the String to URL encode
1312
* @return the URL encoded strings
14-
* @throws GitLabApiException if any exception occurs
1513
*/
16-
public static String urlEncode(String s) throws GitLabApiException {
17-
18-
try {
19-
String encoded = URLEncoder.encode(s, "UTF-8");
20-
// Since the encode method encodes plus signs as %2B,
21-
// we can simply replace the encoded spaces with the correct encoding here
22-
encoded = encoded.replace("+", "%20");
23-
encoded = encoded.replace(".", "%2E");
24-
encoded = encoded.replace("-", "%2D");
25-
encoded = encoded.replace("_", "%5F");
26-
return (encoded);
27-
} catch (Exception e) {
28-
throw new GitLabApiException(e);
29-
}
14+
public static String urlEncode(String s) {
15+
16+
String encoded = URLEncoder.encode(s, StandardCharsets.UTF_8);
17+
// Since the encode method encodes plus signs as %2B,
18+
// we can simply replace the encoded spaces with the correct encoding here
19+
encoded = encoded.replace("+", "%20");
20+
encoded = encoded.replace(".", "%2E");
21+
encoded = encoded.replace("-", "%2D");
22+
encoded = encoded.replace("_", "%5F");
23+
return (encoded);
3024
}
3125
}

0 commit comments

Comments
 (0)