diff --git a/src/main/java/com/deem/zkui/utils/CmdUtil.java b/src/main/java/com/deem/zkui/utils/CmdUtil.java index 37b2f8f..0ce6554 100644 --- a/src/main/java/com/deem/zkui/utils/CmdUtil.java +++ b/src/main/java/com/deem/zkui/utils/CmdUtil.java @@ -22,6 +22,8 @@ import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; +import java.nio.charset.StandardCharsets; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -32,15 +34,17 @@ public enum CmdUtil { public String executeCmd(String cmd, String zkServer, String zkPort) throws IOException { StringBuilder sb; - try (Socket s = new Socket(zkServer, Integer.parseInt(zkPort)); PrintWriter out = new PrintWriter(s.getOutputStream(), true); BufferedReader reader = new BufferedReader(new InputStreamReader(s.getInputStream()))) { - out.println(cmd); - String line = reader.readLine(); - sb = new StringBuilder(); - while (line != null) { + try (Socket s = new Socket(zkServer, Integer.parseInt(zkPort)); + PrintWriter out = new PrintWriter(s.getOutputStream(), true); + BufferedReader reader = new BufferedReader(new InputStreamReader(s.getInputStream(), StandardCharsets.UTF_8))) { + out.println(cmd); + String line = reader.readLine(); + sb = new StringBuilder(); + while (line != null) { sb.append(line); sb.append("
"); line = reader.readLine(); - } + } } return sb.toString(); } diff --git a/src/main/java/com/deem/zkui/utils/ServletUtil.java b/src/main/java/com/deem/zkui/utils/ServletUtil.java index 592a733..1de4ff3 100644 --- a/src/main/java/com/deem/zkui/utils/ServletUtil.java +++ b/src/main/java/com/deem/zkui/utils/ServletUtil.java @@ -23,6 +23,7 @@ import java.io.IOException; import java.io.OutputStreamWriter; import java.io.Writer; +import java.nio.charset.StandardCharsets; import java.util.Arrays; import java.util.HashMap; import java.util.Map; @@ -123,7 +124,7 @@ public void closeZookeeper(ZooKeeper zk) { } public String externalizeNodeValue(byte[] value) { - return value == null ? "" : new String(value).replaceAll("\\n", "\\\\n").replaceAll("\\r", ""); + return value == null ? "" : new String(value, StandardCharsets.UTF_8).replaceAll("\\n", "\\\\n").replaceAll("\\r", ""); // We might want to BASE64 encode it } diff --git a/src/main/java/com/deem/zkui/vo/LeafBean.java b/src/main/java/com/deem/zkui/vo/LeafBean.java index 9b747b8..1cd9fca 100644 --- a/src/main/java/com/deem/zkui/vo/LeafBean.java +++ b/src/main/java/com/deem/zkui/vo/LeafBean.java @@ -61,7 +61,9 @@ public void setValue(byte[] value) { } public String getStrValue() { - return new String(this.value, StandardCharsets.UTF_8); + String strValueTmp = new String(this.value, StandardCharsets.UTF_8); + logger.info("LeafBean GetStrValue: %v",strValueTmp); + return strValueTmp; } public void setStrValue(String strValue) {