From 65dc1d5dbae779939eb45e7aad70110acf260d85 Mon Sep 17 00:00:00 2001 From: Daan Hoogland Date: Sun, 2 Aug 2015 12:48:34 +0200 Subject: [PATCH] CLOUDSTACK-8656: handle template properties loading --- .../storage/template/TemplateLocation.java | 24 ++++--------------- 1 file changed, 4 insertions(+), 20 deletions(-) diff --git a/core/src/com/cloud/storage/template/TemplateLocation.java b/core/src/com/cloud/storage/template/TemplateLocation.java index 87f56b8a79b..ea785b206bd 100644 --- a/core/src/com/cloud/storage/template/TemplateLocation.java +++ b/core/src/com/cloud/storage/template/TemplateLocation.java @@ -94,17 +94,10 @@ public class TemplateLocation { } public boolean load() throws IOException { - FileInputStream strm = null; - try { - strm = new FileInputStream(_file); + try (FileInputStream strm = new FileInputStream(_file);) { _props.load(strm); - } finally { - if (strm != null) { - try { - strm.close(); - } catch (IOException e) { - } - } + } catch (IOException e) { + s_logger.warn("Unable to load the template properties", e); } for (ImageFormat format : ImageFormat.values()) { @@ -142,20 +135,11 @@ public class TemplateLocation { _props.setProperty(info.format.getFileExtension() + ".size", Long.toString(info.size)); _props.setProperty(info.format.getFileExtension() + ".virtualsize", Long.toString(info.virtualSize)); } - FileOutputStream strm = null; - try { - strm = new FileOutputStream(_file); + try (FileOutputStream strm = new FileOutputStream(_file);) { _props.store(strm, ""); } catch (IOException e) { s_logger.warn("Unable to save the template properties ", e); return false; - } finally { - if (strm != null) { - try { - strm.close(); - } catch (IOException e) { - } - } } return true; }