You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jmeter-dev@jakarta.apache.org by se...@apache.org on 2005/06/15 01:45:11 UTC
cvs commit: jakarta-jmeter/src/core/org/apache/jmeter/util JMeterUtils.java
sebb 2005/06/14 16:45:11
Modified: src/core/org/apache/jmeter/util JMeterUtils.java
Log:
New loadProperties() method to get properties from file or classpath
Replace generic Exception with IOException
Revision Changes Path
1.72 +38 -3 jakarta-jmeter/src/core/org/apache/jmeter/util/JMeterUtils.java
Index: JMeterUtils.java
===================================================================
RCS file: /home/cvs/jakarta-jmeter/src/core/org/apache/jmeter/util/JMeterUtils.java,v
retrieving revision 1.71
retrieving revision 1.72
diff -u -r1.71 -r1.72
--- JMeterUtils.java 24 Apr 2005 17:46:17 -0000 1.71
+++ JMeterUtils.java 14 Jun 2005 23:45:11 -0000 1.72
@@ -122,7 +122,7 @@
File f = new File(file);
p.load(new FileInputStream(f));
}
- catch (Exception e)
+ catch (IOException e)
{
try
{
@@ -152,6 +152,41 @@
return p;
}
+ /**
+ * This method loads a property file that
+ * may reside in the user space, or in the classpath
+ *
+ *@param file the file to load
+ *@return the Properties from the file
+ */
+ public static Properties loadProperties(String file)
+ {
+ Properties p = new Properties();
+ try
+ {
+ File f = new File(file);
+ p.load(new FileInputStream(f));
+ }
+ catch (IOException e)
+ {
+ try
+ {
+ InputStream is = JMeterUtils.class.getClassLoader().getResource(file).openStream();
+ if (is == null) {
+ log.warn("Cannot find "+file);
+ return null;
+ }
+ p.load(is);
+ }
+ catch (IOException ex)
+ {
+ log.warn("Error reading "+file+" "+ex.toString());
+ return null;
+ }
+ }
+ return p;
+ }
+
public static PatternCacheLRU getPatternCache()
{
return patternCache;
---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-dev-help@jakarta.apache.org