diff options
| author | tanghao <admin@LAPTOP-QCSKVLI9> | 2021-02-05 19:47:03 +0800 |
|---|---|---|
| committer | tanghao <admin@LAPTOP-QCSKVLI9> | 2021-02-05 19:47:03 +0800 |
| commit | 291ec944ecf1235efd628f70113ab44ed0d26bb1 (patch) | |
| tree | 8bd1f1afcff57557427ff86e61787dce8c35436b /src/main/java/com/nis/util/YamlUtil.java | |
| parent | 6cdb57536914e136fab093e1daf40c98a95a3b85 (diff) | |
fix: 修复EAL4 bug:1.日志相关 2.文件创建工具类修改develop-code-fixdev
Diffstat (limited to 'src/main/java/com/nis/util/YamlUtil.java')
| -rw-r--r-- | src/main/java/com/nis/util/YamlUtil.java | 33 |
1 files changed, 15 insertions, 18 deletions
diff --git a/src/main/java/com/nis/util/YamlUtil.java b/src/main/java/com/nis/util/YamlUtil.java index 93ab6cd..3ca6615 100644 --- a/src/main/java/com/nis/util/YamlUtil.java +++ b/src/main/java/com/nis/util/YamlUtil.java @@ -35,15 +35,13 @@ public class YamlUtil { OutputStreamWriter osw = null;
try {
File file = FileUtil.file(ymlPath);
- out=new FileOutputStream(file);
+ out=FileUtil.getOutputStream(file);
osw=new OutputStreamWriter(out, "UTF-8");
for(String s : param) {
Object load = JSON.parse(s);
y.dump(load,osw);
}
flag = true;
- } catch (FileNotFoundException e) {
- logger.error("snmpYmlHandle error : "+e.getMessage(),e);
} catch (UnsupportedEncodingException e) {
logger.error("snmpYmlHandle error : "+e.getMessage(),e);
} finally {
@@ -90,13 +88,11 @@ public class YamlUtil { ruleYmlfile.delete();
}
- out=new FileOutputStream(file);
+ out=FileUtil.getOutputStream(file);
osw=new OutputStreamWriter(out, "UTF-8");
y.dump(param,osw);
flag = true;
- } catch (FileNotFoundException e) {
- logger.error("subYmlHandle error : "+e.getMessage(),e);
} catch (UnsupportedEncodingException e) {
logger.error("subYmlHandle error : "+e.getMessage(),e);
} finally {
@@ -128,10 +124,12 @@ public class YamlUtil { Yaml y = new Yaml(options);
boolean flag=false;
if(param!=null && !param.isEmpty() && ymlPath != null && ymlPath.length() != 0) {
- FileInputStream fileInputStream =null;
+// FileInputStream fileInputStream =null;
+ BufferedInputStream inputStream = null;
OutputStream out = null;
OutputStreamWriter osw = null;
- FileInputStream fileInputStream2 =null;
+// FileInputStream fileInputStream2 =null;
+ BufferedInputStream inputStream2 = null;
OutputStream out2 = null;
OutputStreamWriter osw2 = null;
try {
@@ -141,13 +139,13 @@ public class YamlUtil { // 文件不存在 创建文件
ruleYmlfile.createNewFile();
}
- fileInputStream2 = new FileInputStream(ruleYmlfile);
- Map<String,Object> map2 = y.loadAs(fileInputStream2, Map.class);
+ inputStream2 = FileUtil.getInputStream(ruleYmlfile);
+ Map<String,Object> map2 = y.loadAs(inputStream2, Map.class);
if(map2==null) {
map2=new HashMap();
}
map2.put("groups", param.get("groups"));
- out2 = new FileOutputStream(ruleYmlfile);
+ out2 = FileUtil.getOutputStream(ruleYmlfile);
osw2 = new OutputStreamWriter(out2, "UTF-8");
y.dump(map2,osw2);
//去除告警规则相关内容
@@ -163,7 +161,7 @@ public class YamlUtil { map.put("alerting", param.get("alerting"));
map.put("rule_files", param.get("rule_files"));**/
- out = new FileOutputStream(ymlfile);
+ out = FileUtil.getOutputStream(ymlfile);
osw = new OutputStreamWriter(out, "UTF-8");
y.dump(param,osw);
@@ -176,8 +174,8 @@ public class YamlUtil { } catch (IOException e) {
logger.error("centerYmlHandle error : "+e.getMessage(),e);
} finally {
- if(fileInputStream!=null) {
- IOUtils.closeQuietly(fileInputStream);
+ if(inputStream!=null) {
+ IOUtils.closeQuietly(inputStream);
}
if(out!=null) {
IOUtils.closeQuietly(out);
@@ -185,8 +183,8 @@ public class YamlUtil { if(osw!=null) {
IOUtils.closeQuietly(osw);
}
- if(fileInputStream2!=null) {
- IOUtils.closeQuietly(fileInputStream2);
+ if(inputStream2!=null) {
+ IOUtils.closeQuietly(inputStream2);
}
if(out2!=null) {
IOUtils.closeQuietly(out2);
@@ -228,7 +226,7 @@ public class YamlUtil { map2 = new HashMap();
}
map2.put("groups", param.get("groups"));
- OutputStream out2 = new FileOutputStream(ruleYmlfile);
+ OutputStream out2 = FileUtil.getOutputStream(ruleYmlfile);
OutputStreamWriter osw2 = new OutputStreamWriter(out2, "UTF-8");
y.dump(map2, osw2);
flag = true;
@@ -259,7 +257,6 @@ public class YamlUtil { public static boolean prometheusStartHandle(String filePath,String param) {
DumperOptions options = new DumperOptions();
options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
- Yaml y = new Yaml(options);
boolean flag=false;
RandomAccessFile raf = null;
try {
|
