Skip to content

Commit f2fc015

Browse files
authored
Use Charset instead of String for Protocol#CHARSET (#2658)
1 parent b1d599d commit f2fc015

File tree

2 files changed

+7
-13
lines changed

2 files changed

+7
-13
lines changed

src/main/java/redis/clients/jedis/Protocol.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package redis.clients.jedis;
22

33
import java.io.IOException;
4+
import java.nio.charset.Charset;
5+
import java.nio.charset.StandardCharsets;
46
import java.util.ArrayList;
57
import java.util.List;
68
import java.util.Locale;
@@ -29,7 +31,7 @@ public final class Protocol {
2931
public static final int DEFAULT_TIMEOUT = 2000;
3032
public static final int DEFAULT_DATABASE = 0;
3133

32-
public static final String CHARSET = "UTF-8";
34+
public static final Charset CHARSET = StandardCharsets.UTF_8;
3335

3436
public static final byte DOLLAR_BYTE = '$';
3537
public static final byte ASTERISK_BYTE = '*';

src/main/java/redis/clients/jedis/util/SafeEncoder.java

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,14 @@ public static byte[][] encodeMany(final String... strs) {
2525
}
2626

2727
public static byte[] encode(final String str) {
28-
try {
29-
if (str == null) {
30-
throw new IllegalArgumentException("null value cannot be sent to redis");
31-
}
32-
return str.getBytes(Protocol.CHARSET);
33-
} catch (UnsupportedEncodingException e) {
34-
throw new JedisException(e);
28+
if (str == null) {
29+
throw new IllegalArgumentException("null value cannot be sent to redis");
3530
}
31+
return str.getBytes(Protocol.CHARSET);
3632
}
3733

3834
public static String encode(final byte[] data) {
39-
try {
40-
return new String(data, Protocol.CHARSET);
41-
} catch (UnsupportedEncodingException e) {
42-
throw new JedisException(e);
43-
}
35+
return new String(data, Protocol.CHARSET);
4436
}
4537

4638
/**

0 commit comments

Comments
 (0)