optimize charset、continue and return
Signed-off-by: slievrly <slievrly@163.com>
This commit is contained in:
parent
cca2ca9752
commit
e01a44702b
@ -18,7 +18,7 @@ package com.alibaba.nacos.api.config.listener;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
/**
|
||||
* Listner Adapter,use default notify thread
|
||||
* Listener Adapter,use default notify thread
|
||||
*
|
||||
* @author water.lyl
|
||||
*/
|
||||
|
@ -73,7 +73,6 @@ public class ConfigFilterChainManager implements IConfigFilterChain {
|
||||
@Override
|
||||
public void doFilter(final IConfigRequest request, final IConfigResponse response) throws NacosException {
|
||||
if (this.currentPosition == this.additionalFilters.size()) {
|
||||
return;
|
||||
} else {
|
||||
this.currentPosition++;
|
||||
IConfigFilter nextFilter = this.additionalFilters.get(this.currentPosition - 1);
|
||||
|
@ -305,7 +305,6 @@ public class ClientWorker {
|
||||
cacheData.setContent(content);
|
||||
LOGGER.warn("[{}] [failover-change] failover file changed. dataId={}, group={}, tenant={}, md5={}, content={}",
|
||||
agent.getName(), dataId, group, tenant, md5, ContentUtils.truncateContent(content));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -285,7 +285,6 @@ public class ServerListManager {
|
||||
List<String> result = new ArrayList<String>(lines.size());
|
||||
for (String serverAddr : lines) {
|
||||
if (null == serverAddr || serverAddr.trim().isEmpty()) {
|
||||
continue;
|
||||
} else {
|
||||
String[] ipPort = serverAddr.trim().split(":");
|
||||
String ip = ipPort[0].trim();
|
||||
|
@ -44,9 +44,7 @@ public class ParamUtils {
|
||||
for (int i = 0; i < length; i++) {
|
||||
char ch = param.charAt(i);
|
||||
if (Character.isLetterOrDigit(ch)) {
|
||||
continue;
|
||||
} else if (isValidChar(ch)) {
|
||||
continue;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
@ -262,7 +262,6 @@ public class ServerListService implements ApplicationListener<WebServerInitializ
|
||||
List<String> ips = new ArrayList<String>(lines.size());
|
||||
for (String serverAddr : lines) {
|
||||
if (null == serverAddr || serverAddr.trim().isEmpty()) {
|
||||
continue;
|
||||
} else {
|
||||
ips.add(getFormatServerAddr(serverAddr));
|
||||
}
|
||||
|
@ -123,7 +123,6 @@ public class NotifySingleService {
|
||||
|
||||
if (null == executors.putIfAbsent(ip, executor)) {
|
||||
logger.warn("[notify-thread-pool] setup thread target ip {} ok.", ip);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -47,9 +47,7 @@ public class ParamUtils {
|
||||
for (int i = 0; i < length; i++) {
|
||||
char ch = param.charAt(i);
|
||||
if (Character.isLetterOrDigit(ch)) {
|
||||
continue;
|
||||
} else if (isValidChar(ch)) {
|
||||
continue;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
@ -24,6 +24,7 @@ import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.*;
|
||||
import java.lang.management.ManagementFactory;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
@ -127,7 +128,8 @@ public class SystemUtils {
|
||||
Reader reader = null;
|
||||
|
||||
try {
|
||||
reader = new InputStreamReader(new FileInputStream(new File(CLUSTER_CONF_FILE_PATH)), UTF_8);
|
||||
reader = new InputStreamReader(new FileInputStream(new File(CLUSTER_CONF_FILE_PATH)),
|
||||
StandardCharsets.UTF_8);
|
||||
List<String> lines = IoUtils.readLines(reader);
|
||||
String comment = "#";
|
||||
for (String line : lines) {
|
||||
|
@ -19,6 +19,7 @@ import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
/**
|
||||
* @author nkorange
|
||||
@ -34,7 +35,7 @@ public class WebUtils {
|
||||
String encoding = req.getParameter("encoding");
|
||||
if (!StringUtils.isEmpty(encoding)) {
|
||||
try {
|
||||
value = new String(value.getBytes("UTF-8"), encoding);
|
||||
value = new String(value.getBytes(StandardCharsets.UTF_8), encoding);
|
||||
} catch (UnsupportedEncodingException ignore) {
|
||||
}
|
||||
}
|
||||
@ -57,7 +58,7 @@ public class WebUtils {
|
||||
String encoding = req.getParameter("encoding");
|
||||
if (!StringUtils.isEmpty(encoding)) {
|
||||
try {
|
||||
value = new String(value.getBytes("UTF-8"), encoding);
|
||||
value = new String(value.getBytes(StandardCharsets.UTF_8), encoding);
|
||||
} catch (UnsupportedEncodingException ignore) {
|
||||
}
|
||||
}
|
||||
|
@ -15,6 +15,8 @@
|
||||
*/
|
||||
package com.alibaba.nacos.naming.acl;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
/**
|
||||
* @author nkorange
|
||||
*/
|
||||
@ -50,7 +52,7 @@ public class AuthInfo {
|
||||
public String toString() {
|
||||
try {
|
||||
// very simple encryption is enough
|
||||
byte[] authBytes = (operator + ":" + appKey).getBytes("UTF-8");
|
||||
byte[] authBytes = (operator + ":" + appKey).getBytes(StandardCharsets.UTF_8);
|
||||
StringBuilder authBuilder = new StringBuilder();
|
||||
for (byte authByte : authBytes) {
|
||||
authBuilder.append((byte) (~((short) authByte))).append(",");
|
||||
|
@ -24,6 +24,7 @@ import com.alibaba.nacos.naming.pojo.Record;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@ -45,17 +46,13 @@ public class FastJsonSerializer implements Serializer {
|
||||
|
||||
@Override
|
||||
public <T> T deserialize(byte[] data, Class<T> clazz) {
|
||||
try {
|
||||
return JSON.parseObject(new String(data, UTF_8), clazz);
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
return null;
|
||||
}
|
||||
return JSON.parseObject(new String(data, StandardCharsets.UTF_8), clazz);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T deserialize(byte[] data, TypeReference<T> clazz) {
|
||||
try {
|
||||
String dataString = new String(data, UTF_8);
|
||||
String dataString = new String(data, StandardCharsets.UTF_8);
|
||||
return JSON.parseObject(dataString, clazz);
|
||||
} catch (Exception e) {
|
||||
Loggers.SRV_LOG.error("deserialize data failed.", e);
|
||||
@ -66,7 +63,7 @@ public class FastJsonSerializer implements Serializer {
|
||||
@Override
|
||||
public <T extends Record> Map<String, Datum<T>> deserializeMap(byte[] data, Class<T> clazz) {
|
||||
try {
|
||||
String dataString = new String(data, UTF_8);
|
||||
String dataString = new String(data, StandardCharsets.UTF_8);
|
||||
Map<String, JSONObject> dataMap = JSON.parseObject(dataString, new TypeReference<Map<String, JSONObject>>() {
|
||||
});
|
||||
|
||||
|
@ -45,6 +45,7 @@ import java.io.UnsupportedEncodingException;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URLDecoder;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.*;
|
||||
import java.util.concurrent.locks.Lock;
|
||||
@ -525,11 +526,11 @@ public class RaftCore {
|
||||
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
GZIPOutputStream gzip = new GZIPOutputStream(out);
|
||||
gzip.write(content.getBytes("UTF-8"));
|
||||
gzip.write(content.getBytes(StandardCharsets.UTF_8));
|
||||
gzip.close();
|
||||
|
||||
byte[] compressedBytes = out.toByteArray();
|
||||
String compressedContent = new String(compressedBytes, "UTF-8");
|
||||
String compressedContent = new String(compressedBytes, StandardCharsets.UTF_8);
|
||||
Loggers.RAFT.info("raw beat data size: {}, size of compressed data: {}",
|
||||
content.length(), compressedContent.length());
|
||||
|
||||
|
@ -38,6 +38,7 @@ import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.channels.FileChannel;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
@ -121,7 +122,7 @@ public class RaftStore {
|
||||
buffer = ByteBuffer.allocate((int) file.length());
|
||||
fc.read(buffer);
|
||||
|
||||
String json = new String(buffer.array(), "UTF-8");
|
||||
String json = new String(buffer.array(), StandardCharsets.UTF_8);
|
||||
if (StringUtils.isBlank(json)) {
|
||||
return null;
|
||||
}
|
||||
@ -222,7 +223,7 @@ public class RaftStore {
|
||||
FileChannel fc = null;
|
||||
ByteBuffer data;
|
||||
|
||||
data = ByteBuffer.wrap(JSON.toJSONString(datum).getBytes("UTF-8"));
|
||||
data = ByteBuffer.wrap(JSON.toJSONString(datum).getBytes(StandardCharsets.UTF_8));
|
||||
|
||||
try {
|
||||
fc = new FileOutputStream(cacheFile, false).getChannel();
|
||||
|
@ -39,6 +39,8 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@ -115,11 +117,11 @@ public class DistroController {
|
||||
for (String key : keys.split(keySplitter)) {
|
||||
datumMap.put(key, consistencyService.get(key));
|
||||
}
|
||||
response.getWriter().write(new String(serializer.serialize(datumMap), "UTF-8"));
|
||||
response.getWriter().write(new String(serializer.serialize(datumMap), StandardCharsets.UTF_8));
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/datums", method = RequestMethod.GET)
|
||||
public void getAllDatums(HttpServletRequest request, HttpServletResponse response) throws Exception {
|
||||
response.getWriter().write(new String(serializer.serialize(dataStore.getDataMap()), "UTF-8"));
|
||||
response.getWriter().write(new String(serializer.serialize(dataStore.getDataMap()), StandardCharsets.UTF_8));
|
||||
}
|
||||
}
|
||||
|
@ -45,6 +45,7 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.net.URLDecoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@ -82,7 +83,7 @@ public class RaftController {
|
||||
@RequestMapping(value = "/beat", method = RequestMethod.POST)
|
||||
public JSONObject beat(HttpServletRequest request, HttpServletResponse response) throws Exception {
|
||||
|
||||
String entity = new String(IoUtils.tryDecompress(request.getInputStream()), "UTF-8");
|
||||
String entity = new String(IoUtils.tryDecompress(request.getInputStream()), StandardCharsets.UTF_8);
|
||||
String value = URLDecoder.decode(entity, "UTF-8");
|
||||
value = URLDecoder.decode(value, "UTF-8");
|
||||
|
||||
|
@ -28,7 +28,6 @@ public class NoneHealthCheckProcessor implements HealthCheckProcessor {
|
||||
|
||||
@Override
|
||||
public void process(HealthCheckTask task) {
|
||||
return;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -44,10 +44,10 @@ public class NetUtils {
|
||||
int[] b = new int[4];
|
||||
String x = "";
|
||||
|
||||
b[0] = (int) ((ip >> 24) & 0xff);
|
||||
b[1] = (int) ((ip >> 16) & 0xff);
|
||||
b[2] = (int) ((ip >> 8) & 0xff);
|
||||
b[3] = (int) (ip & 0xff);
|
||||
b[0] = (ip >> 24) & 0xff;
|
||||
b[1] = (ip >> 16) & 0xff;
|
||||
b[2] = (ip >> 8) & 0xff;
|
||||
b[3] = ip & 0xff;
|
||||
x = Integer.toString(b[0]) + "." + Integer.toString(b[1]) + "." + Integer.toString(b[2]) + "." + Integer.toString(b[3]);
|
||||
|
||||
return x;
|
||||
|
@ -33,6 +33,7 @@ import java.net.DatagramSocket;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.SocketException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.*;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
@ -512,7 +513,7 @@ public class PushService {
|
||||
String dataStr = JSON.toJSONString(data);
|
||||
|
||||
try {
|
||||
byte[] dataBytes = dataStr.getBytes("UTF-8");
|
||||
byte[] dataBytes = dataStr.getBytes(StandardCharsets.UTF_8);
|
||||
dataBytes = compressIfNecessary(dataBytes);
|
||||
|
||||
DatagramPacket packet = new DatagramPacket(dataBytes, dataBytes.length, client.socketAddr);
|
||||
|
@ -626,7 +626,7 @@ public class ConfigAPI_ITCase {
|
||||
*/
|
||||
@Test(timeout = TIME_OUT)
|
||||
public void nacos_removeListener_4() {
|
||||
iconfig.removeListener(dataId, group, (Listener) null);
|
||||
iconfig.removeListener(dataId, group, null);
|
||||
Assert.assertTrue(true);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user