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()) { if (pubKeyFile.exists()) {
String pubKey = cmd.getPubKey(); try (FileOutputStream pubkStream = new FileOutputStream(pubKeyFile)) {
try { pubkStream.write(cmd.getPubKey().getBytes());
FileOutputStream pubkStream = new FileOutputStream(pubKeyFile);
pubkStream.write(pubKey.getBytes());
pubkStream.close();
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
result = "File" + SSHPUBKEYPATH + "is not found:" + e.toString(); result = "File" + SSHPUBKEYPATH + "is not found:"
+ e.toString();
s_logger.debug(result); s_logger.debug(result);
} catch (IOException e) { } catch (IOException e) {
result = "Write file " + SSHPUBKEYPATH + ":" + e.toString(); result = "Write file " + SSHPUBKEYPATH + ":" + e.toString();