sebb        2004/02/18 15:27:21

  Modified:    src/core/org/apache/jmeter/reporters FileReporter.java
  Log:
  Close file on exception
  
  Revision  Changes    Path
  1.14      +54 -48    
jakarta-jmeter/src/core/org/apache/jmeter/reporters/FileReporter.java
  
  Index: FileReporter.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-jmeter/src/core/org/apache/jmeter/reporters/FileReporter.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- FileReporter.java 18 Feb 2004 23:09:22 -0000      1.13
  +++ FileReporter.java 18 Feb 2004 23:27:21 -0000      1.14
  @@ -63,62 +63,68 @@
           File datafile = new File(file);
           BufferedReader reader = null;
   
  -        if (datafile.canRead())
  +        try
           {
  -            reader = new BufferedReader(new FileReader(datafile));
  -        }
  -        else
  -        {
  -            JOptionPane.showMessageDialog(
  -                    null, "The file you specified cannot be read.",
  -                    "Information", JOptionPane.INFORMATION_MESSAGE);
  -            return;
  -        }
  -        String line;
  -
  -        while ((line = reader.readLine()) != null)
  -        {
  -            try
  +            if (datafile.canRead())
               {
  -                line = line.trim();
  -                if (line.startsWith("#") || line.length() == 0)
  -                {
  -                    continue;
  -                }
  -                int splitter = line.lastIndexOf(' ');
  -                String key = line.substring(0, splitter);
  -                int len = line.length() - 1;
  -                Integer value = null;
  -
  -                if (line.charAt(len) == ',')
  +                reader = new BufferedReader(new FileReader(datafile));
  +            }
  +            else
  +            {
  +                JOptionPane.showMessageDialog(
  +                        null, "The file you specified cannot be read.",
  +                        "Information", JOptionPane.INFORMATION_MESSAGE);
  +                return;
  +            }
  +            String line;
  +            
  +            while ((line = reader.readLine()) != null)
  +            {
  +                try
                   {
  -                    value = new Integer(
  -                            line.substring(splitter + 1, len));
  +                    line = line.trim();
  +                    if (line.startsWith("#") || line.length() == 0)
  +                    {
  +                        continue;
  +                    }
  +                    int splitter = line.lastIndexOf(' ');
  +                    String key = line.substring(0, splitter);
  +                    int len = line.length() - 1;
  +                    Integer value = null;
  +            
  +                    if (line.charAt(len) == ',')
  +                    {
  +                        value = new Integer(
  +                                line.substring(splitter + 1, len));
  +                    }
  +                    else
  +                    {
  +                        value = new Integer(
  +                                line.substring(splitter + 1));
  +                    }
  +                    Vector v = getData(key);
  +            
  +                    if (v == null)
  +                    {
  +                        v = new Vector();
  +                        this.data.put(key, v);
  +                    }
  +                    v.addElement(value);
                   }
  -                else
  +                catch (NumberFormatException nfe)
                   {
  -                    value = new Integer(
  -                            line.substring(splitter + 1));
  +                    log.error("This line could not be parsed: " + line, nfe);
                   }
  -                Vector v = getData(key);
  -
  -                if (v == null)
  +                catch (Exception e)
                   {
  -                    v = new Vector();
  -                    this.data.put(key, v);
  +                    log.error("This line caused a problem: " + line, e);
                   }
  -                v.addElement(value);
  -            }
  -            catch (NumberFormatException nfe)
  -            {
  -                log.error("This line could not be parsed: " + line, nfe);
  -            }
  -            catch (Exception e)
  -            {
  -                log.error("This line caused a problem: " + line, e);
               }
           }
  -        reader.close();
  +        finally
  +        {
  +                     reader.close();
  +        }
           showPanel();
       }
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to