From bba2057f370279a3a624b9798d6f23356f18ac86 Mon Sep 17 00:00:00 2001
From: kenneth_suter <kenneth_suter@localhost>
Date: Thu, 16 Aug 2007 20:18:39 +0000
Subject: [PATCH] fixed another stream almost identical to the previously problematic one

---
 opends/src/quicksetup/org/opends/quicksetup/Application.java |  131 +++++++++++++++++++++----------------------
 1 files changed, 64 insertions(+), 67 deletions(-)

diff --git a/opends/src/quicksetup/org/opends/quicksetup/Application.java b/opends/src/quicksetup/org/opends/quicksetup/Application.java
index c640c4a..27f9de7 100644
--- a/opends/src/quicksetup/org/opends/quicksetup/Application.java
+++ b/opends/src/quicksetup/org/opends/quicksetup/Application.java
@@ -752,14 +752,74 @@
    * ProgressUpdateListeners with the formatted messages.
    *
    */
-  protected class ErrorPrintStream extends PrintStream {
+  protected class ErrorPrintStream extends ApplicationPrintStream {
+
+    /**
+     * {@inheritDoc}
+     */
+    public ErrorPrintStream() {
+      super();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    protected Message formatString(String s) {
+      return getFormattedLogError(Message.raw(s));
+    }
+
+  }
+
+  /**
+   * This class is used to notify the ProgressUpdateListeners of events
+   * that are written to the standard output. It is used in WebStartInstaller
+   * and in OfflineInstaller. These classes just create a OutputPrintStream and
+   * then they do a call to System.out with it.
+   *
+   * The class just reads what is written to the standard output, obtains an
+   * formatted representation of it and then notifies the
+   * ProgressUpdateListeners with the formatted messages.
+   *
+   */
+  protected class OutputPrintStream extends ApplicationPrintStream
+  {
+
+    /**
+     * {@inheritDoc}
+     */
+    public OutputPrintStream() {
+      super();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    protected Message formatString(String s) {
+      return getFormattedLog(Message.raw(s));
+    }
+
+  }
+
+  /**
+   * This class is used to notify the ProgressUpdateListeners of events
+   * that are written to the standard streams.
+   */
+  protected abstract class ApplicationPrintStream extends PrintStream {
+
     private boolean isFirstLine;
 
     /**
+     * Format a string before sending a listener notification.
+     * @param string to format
+     * @return formatted message
+     */
+    abstract protected Message formatString(String string);
+
+    /**
      * Default constructor.
      *
      */
-    public ErrorPrintStream()
+    public ApplicationPrintStream()
     {
       super(new ByteArrayOutputStream(), true);
       isFirstLine = true;
@@ -774,11 +834,11 @@
       MessageBuilder mb = new MessageBuilder();
       if (isFirstLine)
       {
-        mb.append(getFormattedLogError(Message.raw(msg)));
+        mb.append(formatString(msg));
       } else
       {
         mb.append(formatter.getLineBreak());
-        mb.append(getFormattedLogError(Message.raw(msg)));
+        mb.append(formatString(msg));
       }
       notifyListeners(mb.toMessage());
       isFirstLine = false;
@@ -803,67 +863,4 @@
       println(new String(b, off, len));
     }
   }
-
-  /**
-   * This class is used to notify the ProgressUpdateListeners of events
-   * that are written to the standard output. It is used in WebStartInstaller
-   * and in OfflineInstaller. These classes just create a OutputPrintStream and
-   * then they do a call to System.out with it.
-   *
-   * The class just reads what is written to the standard output, obtains an
-   * formatted representation of it and then notifies the
-   * ProgressUpdateListeners with the formatted messages.
-   *
-   */
-  protected class OutputPrintStream extends PrintStream
-  {
-    private boolean isFirstLine;
-
-    /**
-     * Default constructor.
-     *
-     */
-    public OutputPrintStream()
-    {
-      super(new ByteArrayOutputStream(), true);
-      isFirstLine = true;
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public void println(Message msg)
-    {
-      MessageBuilder mb = new MessageBuilder();
-      if (isFirstLine)
-      {
-        mb.append(getFormattedLog(Message.raw(msg)));
-      } else
-      {
-        mb.append(formatter.getLineBreak());
-        mb.append(getFormattedLog(Message.raw(msg)));
-      }
-      notifyListeners(mb.toMessage());
-      isFirstLine = false;
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public void write(byte[] b, int off, int len)
-    {
-      if (b == null)
-      {
-        throw new NullPointerException("b is null");
-      }
-
-      if (off + len > b.length)
-      {
-        throw new IndexOutOfBoundsException(
-            "len + off are bigger than the length of the byte array");
-      }
-
-      println(new String(b, off, len));
-    }
-  }
 }

--
Gitblit v1.10.0