cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bhais...@apache.org
Subject [2/2] git commit: updated refs/heads/master to 3d4d152
Date Wed, 03 Jun 2015 22:09:51 GMT
CID 1302976 Scanner in try-with-resource

Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>

This closes #352


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/3d4d1527
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/3d4d1527
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/3d4d1527

Branch: refs/heads/master
Commit: 3d4d15275340bd9bbec76afb535e4a48371ef421
Parents: 109b6e9
Author: Daan Hoogland <daan.hoogland@gmail.com>
Authored: Wed Jun 3 17:31:19 2015 +0200
Committer: Rohit Yadav <rohit.yadav@shapeblue.com>
Committed: Thu Jun 4 00:09:40 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/3d4d1527/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());


Mime
View raw message