mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-09-22 21:55:39 +00:00
avoid resource warnings
This commit is contained in:
+12
-4
@@ -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");
|
||||
|
||||
+4
-2
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user