You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dolphinscheduler.apache.org by li...@apache.org on 2021/10/08 16:41:51 UTC

[dolphinscheduler] branch dev updated: [DS-6276][fix] specify UTF-8 encoding to read file contents (#6466)

This is an automated email from the ASF dual-hosted git repository.

lidongdai pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/dolphinscheduler.git


The following commit(s) were added to refs/heads/dev by this push:
     new 59daf3c  [DS-6276][fix] specify UTF-8 encoding to read file contents (#6466)
59daf3c is described below

commit 59daf3c837c4f9ef99d0f67044cd8129ee30a547
Author: calvinit <54...@qq.com>
AuthorDate: Sat Oct 9 00:40:10 2021 +0800

    [DS-6276][fix] specify UTF-8 encoding to read file contents (#6466)
    
    This closes #6276
---
 .../java/org/apache/dolphinscheduler/common/utils/FileUtils.java     | 3 ++-
 .../java/org/apache/dolphinscheduler/common/utils/FileUtilsTest.java | 5 ++---
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/FileUtils.java b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/FileUtils.java
index 9fa9b5f..9192469 100644
--- a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/FileUtils.java
+++ b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/FileUtils.java
@@ -20,6 +20,7 @@ package org.apache.dolphinscheduler.common.utils;
 import static org.apache.dolphinscheduler.common.Constants.DATA_BASEDIR_PATH;
 import static org.apache.dolphinscheduler.common.Constants.RESOURCE_VIEW_SUFFIXS;
 import static org.apache.dolphinscheduler.common.Constants.RESOURCE_VIEW_SUFFIXS_DEFAULT_VALUE;
+import static org.apache.dolphinscheduler.common.Constants.UTF_8;
 import static org.apache.dolphinscheduler.common.Constants.YYYYMMDDHHMMSS;
 
 import org.apache.commons.io.IOUtils;
@@ -246,7 +247,7 @@ public class FileUtils {
             while ((length = inputStream.read(buffer)) != -1) {
                 output.write(buffer, 0, length);
             }
-            return output.toString();
+            return output.toString(UTF_8);
         } catch (Exception e) {
             logger.error(e.getMessage(), e);
             throw new RuntimeException(e);
diff --git a/dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/utils/FileUtilsTest.java b/dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/utils/FileUtilsTest.java
index 4cbd4ae..86cadc8 100644
--- a/dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/utils/FileUtilsTest.java
+++ b/dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/utils/FileUtilsTest.java
@@ -21,7 +21,6 @@ import static org.apache.dolphinscheduler.common.Constants.YYYYMMDDHHMMSS;
 
 import org.apache.dolphinscheduler.common.Constants;
 
-import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
 
@@ -90,10 +89,10 @@ public class FileUtilsTest {
     public void testWriteContent2File() throws FileNotFoundException {
         // file exists, fmt is invalid
         String filePath = "test/testFile.txt";
-        String content = "正正正faffdasfasdfas";
+        String content = "正正正faffdasfasdfas,한국어; 한글……にほんご\nfrançais";
         FileUtils.writeContent2File(content, filePath);
 
-        String  fileContent = FileUtils.readFile2Str(new FileInputStream(new File(filePath)));
+        String fileContent = FileUtils.readFile2Str(new FileInputStream(filePath));
         Assert.assertEquals(content, fileContent);
     }