Properties loading simplification

- Using the PropertiesUtil methods, the resource handling could be elliminated

Signed-off-by: Laszlo Hornyak <laszlo.hornyak@gmail.com>
This commit is contained in:
Laszlo Hornyak 2014-02-26 22:35:22 +01:00
parent b2023d04ba
commit 55c449aa07
4 changed files with 3 additions and 13 deletions

View File

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

View File

@ -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 {

View File

@ -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;
}
}

View File

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