diff options
| -rw-r--r-- | src/main/java/com/nis/util/YamlUtil.java | 30 |
1 files changed, 27 insertions, 3 deletions
diff --git a/src/main/java/com/nis/util/YamlUtil.java b/src/main/java/com/nis/util/YamlUtil.java index e598d1b..291bd3b 100644 --- a/src/main/java/com/nis/util/YamlUtil.java +++ b/src/main/java/com/nis/util/YamlUtil.java @@ -151,6 +151,9 @@ public class YamlUtil { FileInputStream fileInputStream =null;
OutputStream out = null;
OutputStreamWriter osw = null;
+ FileInputStream fileInputStream2 =null;
+ OutputStream out2 = null;
+ OutputStreamWriter osw2 = null;
try {
// 修改prometheus.yml配置文件
File ymlfile = new File(ymlPath);
@@ -172,14 +175,14 @@ public class YamlUtil { // 文件不存在 创建文件
ruleYmlfile.createNewFile();
}
- FileInputStream fileInputStream2 = new FileInputStream(ruleYmlfile);
+ fileInputStream2 = new FileInputStream(ruleYmlfile);
Map<String,Object> map2 = y.loadAs(fileInputStream2, Map.class);
if(map2==null) {
map2=new HashMap();
}
map2.put("groups", param.get("groups"));
- OutputStream out2 = new FileOutputStream(ruleYmlfile);
- OutputStreamWriter osw2 = new OutputStreamWriter(out2, "UTF-8");
+ out2 = new FileOutputStream(ruleYmlfile);
+ osw2 = new OutputStreamWriter(out2, "UTF-8");
y.dump(map2,osw2);
// RuntimeUtil.run(null, null, new String[]{"/bin/sh", "-c","ps -ef |grep prometheus|grep -v grep|awk \'{print $2}\'|xargs kill -hup"});
@@ -211,6 +214,27 @@ public class YamlUtil { e.printStackTrace();
}
}
+ if(fileInputStream2!=null) {
+ try {
+ fileInputStream.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ if(out2!=null) {
+ try {
+ out.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ if(osw2!=null) {
+ try {
+ osw.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
}
}
return flag;
|
