This is an automated email from the ASF dual-hosted git repository.
casion pushed a commit to branch dev-1.4.0
in repository https://gitbox.apache.org/repos/asf/linkis.git
The following commit(s) were added to refs/heads/dev-1.4.0 by this push:
new 5a59e5b43 properties values support the Chinese (#4521)
5a59e5b43 is described below
commit 5a59e5b43b95c0e8c1b6db7e03e09ca7bbecdba0
Author: ahaoyao <[email protected]>
AuthorDate: Fri May 12 21:12:28 2023 +0800
properties values support the Chinese (#4521)
* properties values support the Chinese
---------
Co-authored-by: ahaoyao <[email protected]>
---
.../linkis/common/conf/BDPConfiguration.scala | 11 ++++--
.../linkis/common/conf/BDPConfigurationTest.java | 41 ++++++++++++++++++++++
.../src/test/resources/linkis.properties | 16 +++++++++
3 files changed, 65 insertions(+), 3 deletions(-)
diff --git
a/linkis-commons/linkis-common/src/main/scala/org/apache/linkis/common/conf/BDPConfiguration.scala
b/linkis-commons/linkis-common/src/main/scala/org/apache/linkis/common/conf/BDPConfiguration.scala
index 55535e533..14febab63 100644
---
a/linkis-commons/linkis-common/src/main/scala/org/apache/linkis/common/conf/BDPConfiguration.scala
+++
b/linkis-commons/linkis-common/src/main/scala/org/apache/linkis/common/conf/BDPConfiguration.scala
@@ -22,7 +22,7 @@ import org.apache.linkis.common.utils.{Logging, Utils}
import org.apache.commons.io.IOUtils
import org.apache.commons.lang3.StringUtils
-import java.io.{File, FileInputStream, InputStream, IOException}
+import java.io._
import java.util.Properties
import java.util.concurrent.TimeUnit
import java.util.concurrent.locks.ReentrantReadWriteLock
@@ -140,15 +140,20 @@ private[conf] object BDPConfiguration extends Logging {
private def initConfig(config: Properties, filePath: String) {
var inputStream: InputStream = null
-
+ var reader: InputStreamReader = null
+ var buff: BufferedReader = null
Utils.tryFinally {
Utils.tryCatch {
inputStream = new FileInputStream(filePath)
- config.load(inputStream)
+ reader = new InputStreamReader(inputStream, "UTF-8")
+ buff = new BufferedReader(reader)
+ config.load(buff)
} { case e: IOException =>
logger.error("Can't load " + filePath, e)
}
} {
+ IOUtils.closeQuietly(buff)
+ IOUtils.closeQuietly(reader)
IOUtils.closeQuietly(inputStream)
}
}
diff --git
a/linkis-commons/linkis-common/src/test/java/org/apache/linkis/common/conf/BDPConfigurationTest.java
b/linkis-commons/linkis-common/src/test/java/org/apache/linkis/common/conf/BDPConfigurationTest.java
new file mode 100644
index 000000000..5a025eb8b
--- /dev/null
+++
b/linkis-commons/linkis-common/src/test/java/org/apache/linkis/common/conf/BDPConfigurationTest.java
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.linkis.common.conf;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+/** BDPConfiguration Tester */
+public class BDPConfigurationTest {
+
+ @Test
+ public void testGetOption() {
+
+ Assertions.assertEquals(
+ "properties支持中文",
+ BDPConfiguration.getOption(
+ CommonVars.apply("linkis.jobhistory.error.msg.tip",
"properties支持中文"))
+ .get());
+
+ Assertions.assertEquals(
+ "properties支持中文(默认)",
+ BDPConfiguration.getOption(
+ CommonVars.apply("linkis.jobhistory.error.msg.tip1",
"properties支持中文(默认)"))
+ .get());
+ }
+}
diff --git a/linkis-commons/linkis-common/src/test/resources/linkis.properties
b/linkis-commons/linkis-common/src/test/resources/linkis.properties
new file mode 100644
index 000000000..230ad85a4
--- /dev/null
+++ b/linkis-commons/linkis-common/src/test/resources/linkis.properties
@@ -0,0 +1,16 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+# http://www.apache.org/licenses/LICENSE-2.0
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+linkis.jobhistory.error.msg.tip=properties支持中文
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]