rocketmq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dongefore...@apache.org
Subject [38/51] [abbrv] incubator-rocketmq git commit: [ROCKETMQ-206] Fix bug when non-1byte character exists in JSON config files.
Date Tue, 06 Jun 2017 03:38:58 GMT
[ROCKETMQ-206] Fix bug when non-1byte character exists in JSON config files.


Project: http://git-wip-us.apache.org/repos/asf/incubator-rocketmq/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-rocketmq/commit/f009ba0b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-rocketmq/tree/f009ba0b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-rocketmq/diff/f009ba0b

Branch: refs/heads/master
Commit: f009ba0b3e7e9166bbb56cdbdb94703db5825ea4
Parents: c8e84ad
Author: yukon <yukon@apache.org>
Authored: Thu May 25 13:48:22 2017 +0800
Committer: dongeforever <zhendongliu92@yeah.net>
Committed: Tue Jun 6 11:37:29 2017 +0800

----------------------------------------------------------------------
 .../java/org/apache/rocketmq/common/MixAll.java | 26 ++++++++------------
 .../org/apache/rocketmq/common/MixAllTest.java  | 20 +++++++++++++++
 2 files changed, 30 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-rocketmq/blob/f009ba0b/common/src/main/java/org/apache/rocketmq/common/MixAll.java
----------------------------------------------------------------------
diff --git a/common/src/main/java/org/apache/rocketmq/common/MixAll.java b/common/src/main/java/org/apache/rocketmq/common/MixAll.java
index e75efd9..36d81d0 100644
--- a/common/src/main/java/org/apache/rocketmq/common/MixAll.java
+++ b/common/src/main/java/org/apache/rocketmq/common/MixAll.java
@@ -18,7 +18,7 @@ package org.apache.rocketmq.common;
 
 import java.io.ByteArrayInputStream;
 import java.io.File;
-import java.io.FileReader;
+import java.io.FileInputStream;
 import java.io.FileWriter;
 import java.io.IOException;
 import java.io.InputStream;
@@ -187,30 +187,24 @@ public class MixAll {
         }
     }
 
-    public static String file2String(final String fileName) {
+    public static String file2String(final String fileName) throws IOException {
         File file = new File(fileName);
         return file2String(file);
     }
 
-    public static String file2String(final File file) {
+    public static String file2String(final File file) throws IOException {
         if (file.exists()) {
-            char[] data = new char[(int) file.length()];
-            boolean result = false;
+            byte[] data = new byte[(int) file.length()];
+            boolean result;
 
-            FileReader fileReader = null;
+            FileInputStream inputStream = null;
             try {
-                fileReader = new FileReader(file);
-                int len = fileReader.read(data);
+                inputStream = new FileInputStream(file);
+                int len = inputStream.read(data);
                 result = len == data.length;
-            } catch (IOException e) {
-                // e.printStackTrace();
             } finally {
-                if (fileReader != null) {
-                    try {
-                        fileReader.close();
-                    } catch (IOException e) {
-                        e.printStackTrace();
-                    }
+                if (inputStream != null) {
+                    inputStream.close();
                 }
             }
 

http://git-wip-us.apache.org/repos/asf/incubator-rocketmq/blob/f009ba0b/common/src/test/java/org/apache/rocketmq/common/MixAllTest.java
----------------------------------------------------------------------
diff --git a/common/src/test/java/org/apache/rocketmq/common/MixAllTest.java b/common/src/test/java/org/apache/rocketmq/common/MixAllTest.java
index 8220981..218b36d 100644
--- a/common/src/test/java/org/apache/rocketmq/common/MixAllTest.java
+++ b/common/src/test/java/org/apache/rocketmq/common/MixAllTest.java
@@ -21,6 +21,10 @@ import java.io.File;
 import java.io.IOException;
 import java.io.PrintWriter;
 import java.net.InetAddress;
+import java.nio.ByteOrder;
+import java.nio.CharBuffer;
+import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
 import java.util.List;
 import java.util.concurrent.atomic.AtomicLong;
 import org.junit.Test;
@@ -68,6 +72,22 @@ public class MixAllTest {
     }
 
     @Test
+    public void testFile2String_WithChinese() throws IOException {
+        String fileName = System.getProperty("java.io.tmpdir") + File.separator + "MixAllTest"
+ System.currentTimeMillis();
+        File file = new File(fileName);
+        if (file.exists()) {
+            file.delete();
+        }
+        file.createNewFile();
+        PrintWriter out = new PrintWriter(fileName);
+        out.write("TestForMixAll_中文");
+        out.close();
+        String string = MixAll.file2String(fileName);
+        assertThat(string).isEqualTo("TestForMixAll_中文");
+        file.delete();
+    }
+
+    @Test
     public void testString2File() throws IOException {
         String fileName = System.getProperty("java.io.tmpdir") + File.separator + "MixAllTest"
+ System.currentTimeMillis();
         MixAll.string2File("MixAll_testString2File", fileName);


Mime
View raw message