You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@eventmesh.apache.org by jo...@apache.org on 2022/12/04 13:19:34 UTC

[incubator-eventmesh] branch master updated: [Enhancement] Reliance on default encoding [FileWebHookConfigOperation] (#2453)

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

jonyang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-eventmesh.git


The following commit(s) were added to refs/heads/master by this push:
     new ccc387bb0 [Enhancement] Reliance on default encoding [FileWebHookConfigOperation] (#2453)
ccc387bb0 is described below

commit ccc387bb07fcdafa0b9b4794f5b37cd712fb56fc
Author: weihubeats <we...@163.com>
AuthorDate: Sun Dec 4 21:19:29 2022 +0800

    [Enhancement] Reliance on default encoding [FileWebHookConfigOperation] (#2453)
    
    * add utf_8
    
    * update buffered close
---
 .../eventmesh/webhook/admin/FileWebHookConfigOperation.java   | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/eventmesh-webhook/eventmesh-webhook-admin/src/main/java/org/apache/eventmesh/webhook/admin/FileWebHookConfigOperation.java b/eventmesh-webhook/eventmesh-webhook-admin/src/main/java/org/apache/eventmesh/webhook/admin/FileWebHookConfigOperation.java
index ff9fb0e7e..f9d9f12c6 100644
--- a/eventmesh-webhook/eventmesh-webhook-admin/src/main/java/org/apache/eventmesh/webhook/admin/FileWebHookConfigOperation.java
+++ b/eventmesh-webhook/eventmesh-webhook-admin/src/main/java/org/apache/eventmesh/webhook/admin/FileWebHookConfigOperation.java
@@ -32,8 +32,10 @@ import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStreamReader;
 import java.io.OutputStreamWriter;
+import java.nio.charset.StandardCharsets;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Objects;
 import java.util.Properties;
 
 import org.slf4j.Logger;
@@ -134,8 +136,8 @@ public class FileWebHookConfigOperation implements WebHookConfigOperation {
 
     private WebHookConfig getWebHookConfigFromFile(File webhookConfigFile) {
         StringBuilder fileContent = new StringBuilder();
-        try (BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(webhookConfigFile)))) {
-            String line = null;
+        try (BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(webhookConfigFile), StandardCharsets.UTF_8))) {
+            String line;
             while ((line = br.readLine()) != null) {
                 fileContent.append(line);
             }
@@ -147,10 +149,11 @@ public class FileWebHookConfigOperation implements WebHookConfigOperation {
     }
 
     public boolean writeToFile(File webhookConfigFile, WebHookConfig webHookConfig) {
-        try (FileOutputStream fos = new FileOutputStream(webhookConfigFile); BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(fos))) {
+        try (FileOutputStream fos = new FileOutputStream(webhookConfigFile);
+             BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(fos, StandardCharsets.UTF_8))) {
             // lock this file, and will auto release after fos close
             fos.getChannel().lock();
-            bw.write(JsonUtils.serialize(webHookConfig));
+            bw.write(Objects.requireNonNull(JsonUtils.serialize(webHookConfig)));
         } catch (IOException e) {
             logger.error("write webhookConfig {} to file error", webHookConfig.getCallbackPath());
             return false;


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@eventmesh.apache.org
For additional commands, e-mail: commits-help@eventmesh.apache.org