Author: sebb
Date: Mon Oct 24 19:53:43 2011
New Revision: 1188338

URL: http://svn.apache.org/viewvc?rev=1188338&view=rev
Log:
Add loadProperties(String, Properties)

Modified:
    jakarta/jmeter/trunk/src/core/org/apache/jmeter/util/JMeterUtils.java

Modified: jakarta/jmeter/trunk/src/core/org/apache/jmeter/util/JMeterUtils.java
URL: 
http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/core/org/apache/jmeter/util/JMeterUtils.java?rev=1188338&r1=1188337&r2=1188338&view=diff
==============================================================================
--- jakarta/jmeter/trunk/src/core/org/apache/jmeter/util/JMeterUtils.java 
(original)
+++ jakarta/jmeter/trunk/src/core/org/apache/jmeter/util/JMeterUtils.java Mon 
Oct 24 19:53:43 2011
@@ -199,7 +199,20 @@ public class JMeterUtils implements Unit
      * @return the Properties from the file, may be null (e.g. file not found)
      */
     public static Properties loadProperties(String file) {
-        Properties p = new Properties();
+        return loadProperties(file, null);
+    }
+
+    /**
+     * This method loads a property file that may reside in the user space, or
+     * in the classpath
+     *
+     * @param file
+     *            the file to load
+     * @param defaultProps a set of default properties
+     * @return the Properties from the file; if it could not be processed, the 
defaultProps are returned.
+     */
+    public static Properties loadProperties(String file, Properties 
defaultProps) {
+        Properties p = new Properties(defaultProps);
         InputStream is = null;
         try {
             File f = new File(file);
@@ -210,17 +223,17 @@ public class JMeterUtils implements Unit
                 final URL resource = 
JMeterUtils.class.getClassLoader().getResource(file);
                 if (resource == null) {
                     log.warn("Cannot find " + file);
-                    return null;
+                    return defaultProps;
                 }
                 is = resource.openStream();
                 if (is == null) {
                     log.warn("Cannot open " + file);
-                    return null;
+                    return defaultProps;
                 }
                 p.load(is);
             } catch (IOException ex) {
                 log.warn("Error reading " + file + " " + ex.toString());
-                return null;
+                return defaultProps;
             }
         } finally {
             JOrphanUtils.closeQuietly(is);



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to