You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by bh...@apache.org on 2015/06/04 00:10:30 UTC
[2/2] git commit: updated refs/heads/4.5 to 5fb86ae
CID 1302976 Scanner in try-with-resource
Signed-off-by: Rohit Yadav <ro...@shapeblue.com>
This closes #352
(cherry picked from commit 3d4d15275340bd9bbec76afb535e4a48371ef421)
Signed-off-by: Rohit Yadav <ro...@shapeblue.com>
Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/5fb86ae3
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/5fb86ae3
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/5fb86ae3
Branch: refs/heads/4.5
Commit: 5fb86ae316d5e6703e2c54075b8d01149ec8e343
Parents: fb50283
Author: Daan Hoogland <da...@gmail.com>
Authored: Wed Jun 3 17:31:19 2015 +0200
Committer: Rohit Yadav <ro...@shapeblue.com>
Committed: Thu Jun 4 00:10:18 2015 +0200
----------------------------------------------------------------------
.../kvm/src/org/apache/cloudstack/utils/linux/CPUStat.java | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/5fb86ae3/plugins/hypervisors/kvm/src/org/apache/cloudstack/utils/linux/CPUStat.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/kvm/src/org/apache/cloudstack/utils/linux/CPUStat.java b/plugins/hypervisors/kvm/src/org/apache/cloudstack/utils/linux/CPUStat.java
index 38b7e8e..d8228a4 100644
--- a/plugins/hypervisors/kvm/src/org/apache/cloudstack/utils/linux/CPUStat.java
+++ b/plugins/hypervisors/kvm/src/org/apache/cloudstack/utils/linux/CPUStat.java
@@ -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());