[izpack-changes] r1730 - izpack-src/trunk/src/lib/com/izforge/izpack/util

noreply at berlios.de noreply at berlios.de
Tue Feb 13 14:50:51 CET 2007


Author: tschwarze
Date: 2007-02-13 14:50:50 +0100 (Tue, 13 Feb 2007)
New Revision: 1730

Added:
   izpack-src/trunk/src/lib/com/izforge/izpack/util/MonitorInputStream.java
Modified:
   izpack-src/trunk/src/lib/com/izforge/izpack/util/FileExecutor.java
Log:
take MonitorInputstream out of FileExecutor, source cosmetics

Modified: izpack-src/trunk/src/lib/com/izforge/izpack/util/FileExecutor.java
===================================================================
--- izpack-src/trunk/src/lib/com/izforge/izpack/util/FileExecutor.java	2007-02-13 13:49:18 UTC (rev 1729)
+++ izpack-src/trunk/src/lib/com/izforge/izpack/util/FileExecutor.java	2007-02-13 13:50:50 UTC (rev 1730)
@@ -21,14 +21,10 @@
 
 package com.izforge.izpack.util;
 
-import java.io.BufferedReader;
-import java.io.BufferedWriter;
 import java.io.File;
 import java.io.IOException;
 import java.io.InputStreamReader;
-import java.io.Reader;
 import java.io.StringWriter;
-import java.io.Writer;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Iterator;
@@ -47,52 +43,6 @@
 public class FileExecutor
 {
 
-    /**
-     * This is a grabber for stdout and stderr. It will be launched once at command execution end
-     * terminates if the apropriate stream runs out of data.
-     * 
-     * @author Olexij Tkatchenko <ot at parcs.de>
-     */
-    private static class MonitorInputStream implements Runnable
-    {
-
-        private BufferedReader reader;
-
-        private BufferedWriter writer;
-
-        private boolean shouldStop = false;
-
-        public MonitorInputStream(Reader in, Writer out)
-        {
-            reader = new BufferedReader(in);
-            writer = new BufferedWriter(out);
-        }
-
-        public void doStop()
-        {
-            shouldStop = true;
-        }
-
-        public void run()
-        {
-            try
-            {
-                String line;
-                while ((line = reader.readLine()) != null)
-                {
-                    writer.write(line);
-                    writer.newLine();
-                    writer.flush();
-                    if (shouldStop) return;
-                }
-            }
-            catch (IOException ioe)
-            {
-                ioe.printStackTrace(System.out);
-            }
-        }
-    }
-
     private boolean stopThread(Thread t, MonitorInputStream m)
     {
         m.doStop();
@@ -102,7 +52,9 @@
             t.join(softTimeout);
         }
         catch (InterruptedException e)
-        {}
+        {
+            // ignore
+        }
 
         if (!t.isAlive()) return true;
 
@@ -113,7 +65,9 @@
             t.join(hardTimeout);
         }
         catch (InterruptedException e)
-        {}
+        {
+            // ignore
+        }
         return !t.isAlive();
     }
 
@@ -284,7 +238,7 @@
         String permissions = "a+x";
 
         // loop through all executables
-        Iterator efileIterator = files.iterator();
+        Iterator efileIterator = this.files.iterator();
         while (exitStatus == 0 && efileIterator.hasNext())
         {
             ExecutableFile efile = (ExecutableFile) efileIterator.next();

Added: izpack-src/trunk/src/lib/com/izforge/izpack/util/MonitorInputStream.java
===================================================================
--- izpack-src/trunk/src/lib/com/izforge/izpack/util/MonitorInputStream.java	2007-02-13 13:49:18 UTC (rev 1729)
+++ izpack-src/trunk/src/lib/com/izforge/izpack/util/MonitorInputStream.java	2007-02-13 13:50:50 UTC (rev 1730)
@@ -0,0 +1,65 @@
+package com.izforge.izpack.util;
+
+import java.io.BufferedReader;
+import java.io.BufferedWriter;
+import java.io.IOException;
+import java.io.Reader;
+import java.io.Writer;
+
+/**
+ * This is a grabber for stdout and stderr. It will be launched once at command execution end
+ * terminates if the apropriate stream runs out of data.
+ * 
+ * @author Olexij Tkatchenko <ot at parcs.de>
+ */
+public class MonitorInputStream implements Runnable
+{
+
+    private BufferedReader reader;
+
+    private BufferedWriter writer;
+
+    private boolean shouldStop = false;
+
+    /**
+     * Construct a new monitor.
+     * 
+     * @param in The input to read.
+     * @param out The writer to write to.
+     */
+    public MonitorInputStream(Reader in, Writer out)
+    {
+        this.reader = new BufferedReader(in);
+        this.writer = new BufferedWriter(out);
+    }
+
+    /**
+     * Request stopping this thread.
+     */
+    public void doStop()
+    {
+        this.shouldStop = true;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void run()
+    {
+        try
+        {
+            String line;
+            while ((line = this.reader.readLine()) != null)
+            {
+                this.writer.write(line);
+                this.writer.newLine();
+                this.writer.flush();
+                if (this.shouldStop) return;
+            }
+        }
+        catch (IOException ioe)
+        {
+            ioe.printStackTrace(System.out);
+        }
+    }
+}
\ No newline at end of file




More information about the izpack-changes mailing list