From 4c484ff6ea57ce79c5072a830e6536ac41c820c3 Mon Sep 17 00:00:00 2001
From: jvergara <jvergara@localhost>
Date: Thu, 15 Mar 2007 15:52:50 +0000
Subject: [PATCH] Fix for issue 528 (Windows Service Definition for Automatic Startup).

---
 opendj-sdk/opends/src/server/org/opends/server/tools/WaitForFileDelete.java |   59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 57 insertions(+), 2 deletions(-)

diff --git a/opendj-sdk/opends/src/server/org/opends/server/tools/WaitForFileDelete.java b/opendj-sdk/opends/src/server/org/opends/server/tools/WaitForFileDelete.java
index 111b11b..a9d9bc4 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/tools/WaitForFileDelete.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/tools/WaitForFileDelete.java
@@ -124,6 +124,7 @@
     IntegerArgument timeout        = null;
     StringArgument  logFilePath    = null;
     StringArgument  targetFilePath = null;
+    StringArgument  outputFilePath = null;
 
     String toolDescription = getMessage(MSGID_WAIT4DEL_TOOL_DESCRIPTION);
     ArgumentParser argParser = new ArgumentParser(CLASS_NAME, toolDescription,
@@ -144,6 +145,13 @@
       argParser.addArgument(logFilePath);
 
 
+      outputFilePath = new StringArgument("outputfile", 'o', "outputFile",
+                                        false, false,
+                                        true, "{path}", null, null,
+                                        MSGID_WAIT4DEL_DESCRIPTION_OUTPUT_FILE);
+      argParser.addArgument(outputFilePath);
+
+
       timeout = new IntegerArgument("timeout", 't', "timeout", true, false,
                                     true, "{seconds}", 60, null, true, 0, false,
                                     0, MSGID_WAIT4DEL_DESCRIPTION_TIMEOUT);
@@ -222,6 +230,35 @@
     }
 
 
+    // If an output file was specified and we could open the log file, open it
+    // and append data to it.
+    RandomAccessFile outputFile = null;
+    long outputFileOffset = 0L;
+    if (logFile != null)
+    {
+      if (outputFilePath.isPresent())
+      {
+        try
+        {
+          File f = new File(outputFilePath.getValue());
+          if (f.exists())
+          {
+            outputFile = new RandomAccessFile(f, "rw");
+            outputFileOffset = outputFile.length();
+            outputFile.seek(outputFileOffset);
+          }
+        }
+        catch (Exception e)
+        {
+          int    msgID   = MSGID_WAIT4DEL_CANNOT_OPEN_OUTPUT_FILE;
+          String message = getMessage(msgID, outputFilePath.getValue(),
+                                    String.valueOf(e));
+          System.err.println(wrapText(message, MAX_LINE_WIDTH));
+
+          outputFile = null;
+        }
+      }
+    }
     // Figure out when to stop waiting.
     long stopWaitingTime;
     try
@@ -257,8 +294,18 @@
             int bytesRead = logFile.read(logBuffer);
             if (bytesRead > 0)
             {
-              System.out.write(logBuffer, 0, bytesRead);
-              System.out.flush();
+              if (outputFile == null)
+              {
+                System.out.write(logBuffer, 0, bytesRead);
+                System.out.flush();
+              }
+              else
+              {
+                // Write on the file.
+                // TODO
+                outputFile.write(logBuffer, 0, bytesRead);
+
+              }
               logFileOffset += bytesRead;
             }
           }
@@ -283,6 +330,14 @@
       }
     }
 
+    if (outputFile != null)
+    {
+      try
+      {
+        outputFile.close();
+      }
+      catch (Throwable t) {}
+    }
 
     if (targetFile.exists())
     {

--
Gitblit v1.10.0