Skip to content

Commit 3e3ded7

Browse files
committed
safely close resource with java 1.7 resource block
Signed-off-by: Laszlo Hornyak <laszlo.hornyak@gmail.com>
1 parent 5e4fec9 commit 3e3ded7

1 file changed

Lines changed: 4 additions & 6 deletions

File tree

‎plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3324,13 +3324,11 @@ protected Answer execute(ModifySshKeysCommand cmd) {
33243324
}
33253325

33263326
if (pubKeyFile.exists()) {
3327-
String pubKey = cmd.getPubKey();
3328-
try {
3329-
FileOutputStream pubkStream = new FileOutputStream(pubKeyFile);
3330-
pubkStream.write(pubKey.getBytes());
3331-
pubkStream.close();
3327+
try (FileOutputStream pubkStream = new FileOutputStream(pubKeyFile)) {
3328+
pubkStream.write(cmd.getPubKey().getBytes());
33323329
} catch (FileNotFoundException e) {
3333-
result = "File" + SSHPUBKEYPATH + "is not found:" + e.toString();
3330+
result = "File" + SSHPUBKEYPATH + "is not found:"
3331+
+ e.toString();
33343332
s_logger.debug(result);
33353333
} catch (IOException e) {
33363334
result = "Write file " + SSHPUBKEYPATH + ":" + e.toString();

0 commit comments

Comments
 (0)