summaryrefslogtreecommitdiff
path: root/src/main/java/com/nis/util/YamlUtil.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/nis/util/YamlUtil.java')
-rw-r--r--src/main/java/com/nis/util/YamlUtil.java33
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 {