avoid resource warnings

This commit is contained in:
Axel Uhl
2013-01-14 10:47:31 +01:00
parent c2b50b288c
commit 01c42c1b87
2 changed files with 16 additions and 6 deletions
@@ -2,6 +2,7 @@ package com.sap.sailing.monitoring.sysinfo;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import org.hyperic.sigar.ProcCpu;
import org.hyperic.sigar.ProcFd;
@@ -62,17 +63,24 @@ public class ProcessInformationImpl implements ProcessInformation {
}
protected String[] readProc(String path) {
BufferedReader reader = null; StringBuffer buf = new StringBuffer("");
BufferedReader reader = null;
StringBuffer buf = new StringBuffer("");
try {
reader = new BufferedReader(new FileReader(path));
String line = "";
while ( (line = reader.readLine() ) != null) {
buf.append(line).append("\n");
}
} catch(Exception ex) {
} catch (Exception ex) {
return new String[]{};
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException e) {
return new String[]{};
}
}
}
return buf.toString().split("\\n");
@@ -54,14 +54,16 @@ public class SystemInformationImpl implements SystemInformation {
}
protected String[] readProc(String path) throws Exception {
BufferedReader reader = null;
try {
reader = new BufferedReader(new FileReader(path));
} catch (FileNotFoundException ex) {
return new String[]{}; /* return empty result */
} finally {
if (reader != null) {
reader.close();
}
}
String line = ""; StringBuffer buf = new StringBuffer();
while ( (line = reader.readLine() ) != null) {
buf.append(line).append("\n");