From 457bb61f0489d58c810330b40c62ccb7e75b602b Mon Sep 17 00:00:00 2001 From: iskl Date: Fri, 20 Jan 2017 11:18:42 +0800 Subject: [PATCH] [ROCKETMQ-59] Change Charset usages in RocketMQSerializable to RocketMQSerializable#CHARSET_UTF8, closes apache/incubator-rocketmq#43 --- .../remoting/protocol/RemotingSerializable.java | 2 +- .../remoting/protocol/RocketMQSerializable.java | 17 ++++++++--------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/remoting/src/main/java/org/apache/rocketmq/remoting/protocol/RemotingSerializable.java b/remoting/src/main/java/org/apache/rocketmq/remoting/protocol/RemotingSerializable.java index a9c0a629..f80ff14c 100644 --- a/remoting/src/main/java/org/apache/rocketmq/remoting/protocol/RemotingSerializable.java +++ b/remoting/src/main/java/org/apache/rocketmq/remoting/protocol/RemotingSerializable.java @@ -20,7 +20,7 @@ import com.alibaba.fastjson.JSON; import java.nio.charset.Charset; public abstract class RemotingSerializable { - public final static Charset CHARSET_UTF8 = Charset.forName("UTF-8"); + private final static Charset CHARSET_UTF8 = Charset.forName("UTF-8"); public static byte[] encode(final Object obj) { final String json = toJson(obj, false); diff --git a/remoting/src/main/java/org/apache/rocketmq/remoting/protocol/RocketMQSerializable.java b/remoting/src/main/java/org/apache/rocketmq/remoting/protocol/RocketMQSerializable.java index 0ebe795a..86dab46d 100644 --- a/remoting/src/main/java/org/apache/rocketmq/remoting/protocol/RocketMQSerializable.java +++ b/remoting/src/main/java/org/apache/rocketmq/remoting/protocol/RocketMQSerializable.java @@ -23,14 +23,14 @@ import java.util.Iterator; import java.util.Map; public class RocketMQSerializable { - public static final Charset CHARSET_UTF8 = Charset.forName("UTF-8"); + private static final Charset CHARSET_UTF8 = Charset.forName("UTF-8"); public static byte[] rocketMQProtocolEncode(RemotingCommand cmd) { // String remark byte[] remarkBytes = null; int remarkLen = 0; if (cmd.getRemark() != null && cmd.getRemark().length() > 0) { - remarkBytes = cmd.getRemark().getBytes(RemotingSerializable.CHARSET_UTF8); + remarkBytes = cmd.getRemark().getBytes(CHARSET_UTF8); remarkLen = remarkBytes.length; } @@ -89,9 +89,9 @@ public class RocketMQSerializable { if (entry.getKey() != null && entry.getValue() != null) { kvLength = // keySize + Key - 2 + entry.getKey().getBytes(RemotingSerializable.CHARSET_UTF8).length + 2 + entry.getKey().getBytes(CHARSET_UTF8).length // valSize + val - + 4 + entry.getValue().getBytes(RemotingSerializable.CHARSET_UTF8).length; + + 4 + entry.getValue().getBytes(CHARSET_UTF8).length; totalLength += kvLength; } } @@ -103,8 +103,8 @@ public class RocketMQSerializable { while (it.hasNext()) { Map.Entry entry = it.next(); if (entry.getKey() != null && entry.getValue() != null) { - key = entry.getKey().getBytes(RemotingSerializable.CHARSET_UTF8); - val = entry.getValue().getBytes(RemotingSerializable.CHARSET_UTF8); + key = entry.getKey().getBytes(CHARSET_UTF8); + val = entry.getValue().getBytes(CHARSET_UTF8); content.putShort((short) key.length); content.put(key); @@ -154,7 +154,7 @@ public class RocketMQSerializable { if (remarkLength > 0) { byte[] remarkContent = new byte[remarkLength]; headerBuffer.get(remarkContent); - cmd.setRemark(new String(remarkContent, RemotingSerializable.CHARSET_UTF8)); + cmd.setRemark(new String(remarkContent, CHARSET_UTF8)); } // HashMap extFields @@ -187,8 +187,7 @@ public class RocketMQSerializable { valContent = new byte[valSize]; byteBuffer.get(valContent); - map.put(new String(keyContent, RemotingSerializable.CHARSET_UTF8), new String(valContent, - RemotingSerializable.CHARSET_UTF8)); + map.put(new String(keyContent, CHARSET_UTF8), new String(valContent, CHARSET_UTF8)); } return map; } -- GitLab