cvs commit: jakarta-jmeter/src/core/org/apache/jmeter/util JMeterUtils.java

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

cvs commit: jakarta-jmeter/src/core/org/apache/jmeter/util JMeterUtils.java

sebb-3
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: [hidden email]
For additional commands, e-mail: [hidden email]