mirror of https://github.com/apache/cloudstack.git
CID 1302976 Scanner in try-with-resource
Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
This closes #352
(cherry picked from commit 3d4d152753)
Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
This commit is contained in:
parent
fb50283fbe
commit
5fb86ae316
|
|
@ -17,12 +17,12 @@
|
|||
|
||||
package org.apache.cloudstack.utils.linux;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.util.Scanner;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
public class CPUStat {
|
||||
private static final Logger s_logger = Logger.getLogger(CPUStat.class);
|
||||
|
||||
|
|
@ -52,8 +52,9 @@ public class CPUStat {
|
|||
|
||||
private UptimeStats getUptimeAndCpuIdleTime() {
|
||||
UptimeStats uptime = new UptimeStats(0d, 0d);
|
||||
try {
|
||||
String[] stats = new Scanner(new File(_uptimeFile)).useDelimiter("\\Z").next().split("\\s+");
|
||||
File f = new File(_uptimeFile);
|
||||
try (Scanner scanner = new Scanner(f);) {
|
||||
String[] stats = scanner.useDelimiter("\\Z").next().split("\\s+");
|
||||
uptime = new UptimeStats(Double.parseDouble(stats[0]), Double.parseDouble(stats[1]));
|
||||
} catch (FileNotFoundException ex) {
|
||||
s_logger.warn("File " + _uptimeFile + " not found:" + ex.toString());
|
||||
|
|
|
|||
Loading…
Reference in New Issue