safely close resource with java 1.7 resource block

Signed-off-by: Laszlo Hornyak <[email protected]>


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

Branch: refs/heads/master
Commit: 3e3ded75f48abf748ab37cfade4ebfe69fdeffd7
Parents: 5e4fec9
Author: Laszlo Hornyak <[email protected]>
Authored: Sun Feb 9 18:27:54 2014 +0100
Committer: Laszlo Hornyak <[email protected]>
Committed: Sun Feb 9 18:27:54 2014 +0100

----------------------------------------------------------------------
 .../hypervisor/kvm/resource/LibvirtComputingResource.java | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3e3ded75/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java
----------------------------------------------------------------------
diff --git 
a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java
 
b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java
index 053dbc0..62c129b 100755
--- 
a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java
+++ 
b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java
@@ -3324,13 +3324,11 @@ public class LibvirtComputingResource extends 
ServerResourceBase implements Serv
         }
 
         if (pubKeyFile.exists()) {
-            String pubKey = cmd.getPubKey();
-            try {
-                FileOutputStream pubkStream = new FileOutputStream(pubKeyFile);
-                pubkStream.write(pubKey.getBytes());
-                pubkStream.close();
+            try (FileOutputStream pubkStream = new 
FileOutputStream(pubKeyFile)) {
+                pubkStream.write(cmd.getPubKey().getBytes());
             } catch (FileNotFoundException e) {
-                result = "File" + SSHPUBKEYPATH + "is not found:" + 
e.toString();
+                result = "File" + SSHPUBKEYPATH + "is not found:"
+                        + e.toString();
                 s_logger.debug(result);
             } catch (IOException e) {
                 result = "Write file " + SSHPUBKEYPATH + ":" + e.toString();

Reply via email to