From b3b17b231e2f2840332ce6eb96f791865fdec6d5 Mon Sep 17 00:00:00 2001
From: zhubaomin <zhubaomin>
Date: 星期一, 14 四月 2025 16:38:16 +0800
Subject: [PATCH] 代码优化
---
pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/util/ConfigProperties.java | 83 +++++++++++++++++++++++++++++++++++++++++
1 files changed, 83 insertions(+), 0 deletions(-)
diff --git a/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/util/ConfigProperties.java b/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/util/ConfigProperties.java
new file mode 100644
index 0000000..52714b0
--- /dev/null
+++ b/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/util/ConfigProperties.java
@@ -0,0 +1,83 @@
+package com.dy.common.util;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map.Entry;
+import java.util.Properties;
+
+@SuppressWarnings("unused")
+public class ConfigProperties {
+ private static HashMap<String, String> properties = new HashMap<>();
+
+ private ConfigProperties() {
+ }
+
+ /**
+ * 鏄惁鏈夊睘鎬т簡
+ * @return 瀛樺湪灞炴�ч厤缃繑鍥瀟rue锛屽惁鍒欒繑鍥瀎alse
+ */
+ public static boolean hasProperties(){
+ return properties != null && properties.size() > 0;
+ }
+
+ /**
+ * 鏍规嵁閰嶇疆鍚嶇О寰楀埌閰嶇疆鍊�
+ *
+ * @param name 灞炴�у悕
+ * @return 灞炴�у��
+ */
+ public static String getConfig(String name) {
+ if (properties == null) {
+ return null;
+ }
+ if(name.trim().equals("")){
+ return "" ;
+ }
+ return properties.get(name);
+ }
+
+ /**
+ * 鍒濆鍖栭厤缃�
+ *
+ * @param in 杈撳叆娴�
+ * @param repeatCover 鏄惁閲嶅
+ * @throws Exception 鎶涘嚭寮傚父
+ */
+ public static void init(InputStream in, boolean repeatCover) throws Exception {
+ if(in == null){
+ throw new Exception("灞炴�ч厤缃枃浠朵笉瀛樺湪锛�") ;
+ }
+ if(properties.size() > 0){
+ if(repeatCover){
+ parseProperties(in);
+ }
+ }else{
+ parseProperties(in);
+ }
+ }
+
+ /**
+ * 閲嶆柊鍒濆鍖�
+ *
+ * @param in 杈撳叆娴�
+ * @throws Exception 鎶涘嚭寮傚父
+ */
+ public static void reInit(InputStream in) throws Exception {
+ properties = new HashMap<>();
+ parseProperties(in);
+ }
+
+
+ private static void parseProperties(InputStream in) throws IOException{
+ Properties prop = new Properties();
+ prop.load(in);
+ Iterator<Entry<Object, Object>> it = prop.entrySet().iterator() ;
+ Entry<Object, Object> entry ;
+ while(it.hasNext()){
+ entry = it.next() ;
+ properties.put((String)entry.getKey(), (String)entry.getValue()) ;
+ }
+ }
+}
--
Gitblit v1.8.0