Skip to content

Commit 55c449a

Browse files
committed
Properties loading simplification
- Using the PropertiesUtil methods, the resource handling could be elliminated Signed-off-by: Laszlo Hornyak <laszlo.hornyak@gmail.com>
1 parent b2023d0 commit 55c449a

4 files changed

Lines changed: 3 additions & 13 deletions

File tree

agent/src/com/cloud/agent/AgentShell.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,8 @@
1717
package com.cloud.agent;
1818

1919
import java.io.File;
20-
import java.io.FileInputStream;
2120
import java.io.FileNotFoundException;
2221
import java.io.IOException;
23-
import java.io.InputStream;
2422
import java.lang.reflect.Constructor;
2523
import java.lang.reflect.InvocationTargetException;
2624
import java.util.ArrayList;
@@ -37,7 +35,6 @@
3735
import org.apache.commons.daemon.Daemon;
3836
import org.apache.commons.daemon.DaemonContext;
3937
import org.apache.commons.daemon.DaemonInitException;
40-
import org.apache.commons.io.IOUtils;
4138
import org.apache.commons.lang.math.NumberUtils;
4239
import org.apache.log4j.Logger;
4340
import org.apache.log4j.xml.DOMConfigurator;
@@ -174,16 +171,12 @@ void loadProperties() throws ConfigurationException {
174171

175172
s_logger.info("agent.properties found at " + file.getAbsolutePath());
176173

177-
InputStream propertiesStream = null;
178174
try {
179-
propertiesStream = new FileInputStream(file);
180-
_properties.load(propertiesStream);
175+
PropertiesUtil.loadFromFile(_properties, file);
181176
} catch (final FileNotFoundException ex) {
182177
throw new CloudRuntimeException("Cannot find the file: " + file.getAbsolutePath(), ex);
183178
} catch (final IOException ex) {
184179
throw new CloudRuntimeException("IOException in reading " + file.getAbsolutePath(), ex);
185-
} finally {
186-
IOUtils.closeQuietly(propertiesStream);
187180
}
188181
}
189182

agent/test/com/cloud/agent/AgentShellTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@
2020

2121
import javax.naming.ConfigurationException;
2222

23-
import junit.framework.Assert;
24-
23+
import org.junit.Assert;
2524
import org.junit.Test;
2625

2726
public class AgentShellTest {

utils/src/com/cloud/utils/PropertiesUtil.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import java.util.Properties;
3131
import java.util.Set;
3232

33-
import org.apache.commons.io.IOUtils;
3433
import org.apache.log4j.Logger;
3534

3635
public class PropertiesUtil {
@@ -187,5 +186,5 @@ public static Properties loadFromFile(final File file)
187186
loadFromFile(properties, file);
188187
return properties;
189188
}
190-
189+
191190
}

utils/src/com/cloud/utils/script/Script.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121

2222
import java.io.BufferedReader;
2323
import java.io.File;
24-
import java.io.FileInputStream;
2524
import java.io.IOException;
2625
import java.io.InputStreamReader;
2726
import java.io.PrintWriter;

0 commit comments

Comments
 (0)