geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdil...@apache.org
Subject svn commit: r577447 - /geronimo/sandbox/gshell/trunk/gshell-command-api/src/main/java/org/apache/geronimo/gshell/command/IO.java
Date Wed, 19 Sep 2007 21:22:03 GMT
Author: jdillon
Date: Wed Sep 19 14:22:03 2007
New Revision: 577447

URL: http://svn.apache.org/viewvc?rev=577447&view=rev
Log:
Added better handling when the out and err streams are the same

Modified:
    geronimo/sandbox/gshell/trunk/gshell-command-api/src/main/java/org/apache/geronimo/gshell/command/IO.java

Modified: geronimo/sandbox/gshell/trunk/gshell-command-api/src/main/java/org/apache/geronimo/gshell/command/IO.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-command-api/src/main/java/org/apache/geronimo/gshell/command/IO.java?rev=577447&r1=577446&r2=577447&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-command-api/src/main/java/org/apache/geronimo/gshell/command/IO.java
(original)
+++ geronimo/sandbox/gshell/trunk/gshell-command-api/src/main/java/org/apache/geronimo/gshell/command/IO.java
Wed Sep 19 14:22:03 2007
@@ -104,9 +104,17 @@
         //       be ANSI-aware instead of this...
         //
 
+
         this.out = new RenderWriter(outputStream, autoFlush);
-        this.err = new RenderWriter(errorStream, autoFlush);
-        
+
+        /// Don't rewrite the error stream if we have the same stream for out and error
+        if (isSharedOutputStreams()) {
+            this.err = this.out;
+        }
+        else {
+            this.err = new RenderWriter(errorStream, autoFlush);
+        }
+
         // this.out = new PrintWriter(out, autoFlush);
         // this.err = new PrintWriter(err, autoFlush);
     }
@@ -154,7 +162,15 @@
     public String toString() {
         return ReflectionToStringBuilder.toString(this);
     }
+
+    //
+    // FIXME: Find a better name for this method.
+    //
     
+    public boolean isSharedOutputStreams() {
+        return outputStream == errorStream;
+    }
+
     /**
      * Set the verbosity level.
      *
@@ -209,7 +225,11 @@
      */
     public void flush() {
         out.flush();
-        err.flush();
+
+        // Only attempt to flush the err stream if we aren't sharing it with out
+        if (!isSharedOutputStreams()) {
+            err.flush();
+        }
     }
 
     /**
@@ -218,7 +238,11 @@
     public void close() throws IOException {
         IOUtil.close(in);
         IOUtil.close(out);
-        IOUtil.close(err);
+
+        // Only attempt to close the err stream if we aren't sharing it with out
+        if (!isSharedOutputStreams()) {
+            IOUtil.close(err);
+        }
     }
 
     //



Mime
View raw message