safely close resource with java 1.7 resource block

Signed-off-by: Laszlo Hornyak <laszlo.hornyak@gmail.com>
This commit is contained in:
Laszlo Hornyak 2014-02-09 18:27:54 +01:00
parent 5e4fec9eca
commit 3e3ded75f4

View File

@ -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();