[jbosscache-commits] JBoss Cache SVN: r5017 - cache-bench-fwk/trunk/src/org/cachebench/reportgenerators.

jbosscache-commits at lists.jboss.org jbosscache-commits at lists.jboss.org
Sun Jan 6 18:05:50 EST 2008


Author: mircea.markus
Date: 2008-01-06 18:05:50 -0500 (Sun, 06 Jan 2008)
New Revision: 5017

Modified:
   cache-bench-fwk/trunk/src/org/cachebench/reportgenerators/CSVReportGenerator.java
Log:


Modified: cache-bench-fwk/trunk/src/org/cachebench/reportgenerators/CSVReportGenerator.java
===================================================================
--- cache-bench-fwk/trunk/src/org/cachebench/reportgenerators/CSVReportGenerator.java	2008-01-06 22:48:42 UTC (rev 5016)
+++ cache-bench-fwk/trunk/src/org/cachebench/reportgenerators/CSVReportGenerator.java	2008-01-06 23:05:50 UTC (rev 5017)
@@ -34,6 +34,8 @@
       {
          BufferedWriter writer = null;
          log.debug("Opening output file [" + output + "]");
+         String fileName = output.getAbsolutePath() + ".old." + System.currentTimeMillis();
+         prepareReportFile(fileName);
          writer = new BufferedWriter(new FileWriter(output));
          writeHeaderLine(writer); // Write the Header of the Report
          // Write the results
@@ -51,8 +53,7 @@
          log.debug("Report complete");
          if  (output.exists())
          {
-            log.error("Expected report file:'" + output.getAbsoluteFile() + "'does not exist!");
-            throw new IllegalStateException("The report file does not exist - weird!");
+            log.warn("Expected report file:'" + output.getAbsoluteFile() + "'does not exist!");
          }
       } catch (IOException e)
       {
@@ -60,6 +61,25 @@
       }
    }
 
+   private void prepareReportFile(String fileName)
+         throws IOException
+   {
+      if (output.exists())
+      {
+         log.info("A file named: '" + output.getAbsolutePath() + "' already exist. Renaming to '" + fileName + "'");
+         if (output.renameTo(new File(fileName))) {
+            log.warn("Could not rename!!!");
+         }
+      } else
+      {
+         if (output.createNewFile()) {
+            log.info("Successfully created report file:" + output.getAbsolutePath());
+         } else {
+            log.warn("Failed to create the report file!");
+         }
+      }
+   }
+
    /**
     * Writes out the report.
     * The method checkes whether the result is passed or failed. And based on the status would generate the report with




More information about the jbosscache-commits mailing list