diff options
| author | tanghao <default@DESKTOP-7FEGRP2> | 2020-07-31 14:35:57 +0800 |
|---|---|---|
| committer | tanghao <default@DESKTOP-7FEGRP2> | 2020-07-31 14:35:57 +0800 |
| commit | 6523455b8fa9baa91920071f18c3bc22ec163ed4 (patch) | |
| tree | 06979b1ca0f4226baf8af8e4ec6f98d79a69fa2c | |
| parent | 9b3c010eeb0f64a6c452f552062fdc412b7a079e (diff) | |
fix: 关闭没有处理的流
| -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;
|
