From 55c449aa07f39e4d06f96b19f70e6669f6e055bd Mon Sep 17 00:00:00 2001 From: Laszlo Hornyak Date: Wed, 26 Feb 2014 22:35:22 +0100 Subject: [PATCH] Properties loading simplification - Using the PropertiesUtil methods, the resource handling could be elliminated Signed-off-by: Laszlo Hornyak --- agent/src/com/cloud/agent/AgentShell.java | 9 +-------- agent/test/com/cloud/agent/AgentShellTest.java | 3 +-- utils/src/com/cloud/utils/PropertiesUtil.java | 3 +-- utils/src/com/cloud/utils/script/Script.java | 1 - 4 files changed, 3 insertions(+), 13 deletions(-) diff --git a/agent/src/com/cloud/agent/AgentShell.java b/agent/src/com/cloud/agent/AgentShell.java index 67b7b2fa4ad..34e73ed37a3 100644 --- a/agent/src/com/cloud/agent/AgentShell.java +++ b/agent/src/com/cloud/agent/AgentShell.java @@ -17,10 +17,8 @@ package com.cloud.agent; import java.io.File; -import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; -import java.io.InputStream; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; @@ -37,7 +35,6 @@ import javax.naming.ConfigurationException; import org.apache.commons.daemon.Daemon; import org.apache.commons.daemon.DaemonContext; import org.apache.commons.daemon.DaemonInitException; -import org.apache.commons.io.IOUtils; import org.apache.commons.lang.math.NumberUtils; import org.apache.log4j.Logger; import org.apache.log4j.xml.DOMConfigurator; @@ -174,16 +171,12 @@ public class AgentShell implements IAgentShell, Daemon { s_logger.info("agent.properties found at " + file.getAbsolutePath()); - InputStream propertiesStream = null; try { - propertiesStream = new FileInputStream(file); - _properties.load(propertiesStream); + PropertiesUtil.loadFromFile(_properties, file); } catch (final FileNotFoundException ex) { throw new CloudRuntimeException("Cannot find the file: " + file.getAbsolutePath(), ex); } catch (final IOException ex) { throw new CloudRuntimeException("IOException in reading " + file.getAbsolutePath(), ex); - } finally { - IOUtils.closeQuietly(propertiesStream); } } diff --git a/agent/test/com/cloud/agent/AgentShellTest.java b/agent/test/com/cloud/agent/AgentShellTest.java index 1f60d87ff29..5baa7bf800e 100644 --- a/agent/test/com/cloud/agent/AgentShellTest.java +++ b/agent/test/com/cloud/agent/AgentShellTest.java @@ -20,8 +20,7 @@ import java.util.UUID; import javax.naming.ConfigurationException; -import junit.framework.Assert; - +import org.junit.Assert; import org.junit.Test; public class AgentShellTest { diff --git a/utils/src/com/cloud/utils/PropertiesUtil.java b/utils/src/com/cloud/utils/PropertiesUtil.java index 1375463bbce..fe5a366033e 100755 --- a/utils/src/com/cloud/utils/PropertiesUtil.java +++ b/utils/src/com/cloud/utils/PropertiesUtil.java @@ -30,7 +30,6 @@ import java.util.Map; import java.util.Properties; import java.util.Set; -import org.apache.commons.io.IOUtils; import org.apache.log4j.Logger; public class PropertiesUtil { @@ -187,5 +186,5 @@ public class PropertiesUtil { loadFromFile(properties, file); return properties; } - + } diff --git a/utils/src/com/cloud/utils/script/Script.java b/utils/src/com/cloud/utils/script/Script.java index b8a86689e38..014432ed461 100755 --- a/utils/src/com/cloud/utils/script/Script.java +++ b/utils/src/com/cloud/utils/script/Script.java @@ -21,7 +21,6 @@ package com.cloud.utils.script; import java.io.BufferedReader; import java.io.File; -import java.io.FileInputStream; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter;