CID 1302974: Scanner in try-with-resource

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

This closes #353
This commit is contained in:
Daan Hoogland 2015-06-03 17:37:13 +02:00 committed by Rohit Yadav
parent 9c2a1ea81e
commit 109b6e94d3

View File

@ -16,11 +16,10 @@
// under the License.
package org.apache.cloudstack.utils.linux;
import java.util.HashMap;
import java.util.Map;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
public class MemStat {
@ -29,7 +28,7 @@ public class MemStat {
protected final static String CACHE_KEY = "Cached";
protected final static String TOTAL_KEY = "MemTotal";
private Map<String, Double> _memStats = new HashMap<String, Double>();
private final Map<String, Double> _memStats = new HashMap<String, Double>();
public MemStat() {
}
@ -51,9 +50,9 @@ public class MemStat {
}
public void refresh() {
try {
Scanner fileScanner = new Scanner(new File(MEMINFO_FILE));
parseFromScanner(fileScanner);
File f = new File(MEMINFO_FILE);
try (Scanner scanner = new Scanner(f)) {
parseFromScanner(scanner);
} catch (FileNotFoundException ex) {
throw new RuntimeException("File " + MEMINFO_FILE + " not found:" + ex.toString());
}