"UTF-8" -> StandardCharsets.UTF_8
@@ -6,6 +6,7 @@ import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.io.Serializable;
+import java.nio.charset.StandardCharsets;
import java.text.SimpleDateFormat;
import java.util.Date;
@@ -19,18 +20,18 @@ public class ExternalKeyUtil {
if (newKey == null) {
throw new NullPointerException("key can't be null");
}
- byte[] keyBytesWithOutPrefix = null;
+ byte[] keyBytesWithOutPrefix;
if (newKey instanceof String) {
- keyBytesWithOutPrefix = newKey.toString().getBytes("UTF-8");
+ keyBytesWithOutPrefix = newKey.toString().getBytes(StandardCharsets.UTF_8);
} else if (newKey instanceof byte[]) {
keyBytesWithOutPrefix = (byte[]) newKey;
} else if (newKey instanceof Number) {
- keyBytesWithOutPrefix = (newKey.getClass().getSimpleName() + newKey).getBytes("UTF-8");
+ keyBytesWithOutPrefix = (newKey.getClass().getSimpleName() + newKey).getBytes(StandardCharsets.UTF_8);
} else if (newKey instanceof Date) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss,SSS");
keyBytesWithOutPrefix = (newKey.getClass().getSimpleName() + sdf.format(newKey)).getBytes();
} else if (newKey instanceof Boolean) {
- keyBytesWithOutPrefix = newKey.toString().getBytes("UTF-8");
+ keyBytesWithOutPrefix = newKey.toString().getBytes(StandardCharsets.UTF_8);
} else if (newKey instanceof Serializable) {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream os = new ObjectOutputStream(bos);
@@ -41,7 +42,7 @@ public class ExternalKeyUtil {
} else {
throw new CacheException("can't convert key of class: " + newKey.getClass());
}
- byte[] prefixBytes = prefix.getBytes("UTF-8");
+ byte[] prefixBytes = prefix.getBytes(StandardCharsets.UTF_8);
byte[] rt = new byte[prefixBytes.length + keyBytesWithOutPrefix.length];
System.arraycopy(prefixBytes, 0, rt, 0, prefixBytes.length);
System.arraycopy(keyBytesWithOutPrefix, 0, rt, prefixBytes.length, keyBytesWithOutPrefix.length);
