directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pamarce...@apache.org
Subject svn commit: r1477557 - /directory/studio/trunk/plugins/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/ConsolePrinterThread.java
Date Tue, 30 Apr 2013 11:12:59 GMT
Author: pamarcelot
Date: Tue Apr 30 11:12:59 2013
New Revision: 1477557

URL: http://svn.apache.org/r1477557
Log:
Fix for DIRSTUDIO-905 (IOException (Document is closed) thrown when quitting Apache Directory
Studio with an LDAP Server running).

Added javadocs as well.

Modified:
    directory/studio/trunk/plugins/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/ConsolePrinterThread.java

Modified: directory/studio/trunk/plugins/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/ConsolePrinterThread.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/ConsolePrinterThread.java?rev=1477557&r1=1477556&r2=1477557&view=diff
==============================================================================
--- directory/studio/trunk/plugins/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/ConsolePrinterThread.java
(original)
+++ directory/studio/trunk/plugins/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/ConsolePrinterThread.java
Tue Apr 30 11:12:59 2013
@@ -29,13 +29,29 @@ import java.io.IOException;
 import org.eclipse.ui.console.MessageConsoleStream;
 
 
+/**
+ * This class implements a thread used to print in the console the contents of a file.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
 public class ConsolePrinterThread extends Thread
 {
+    /** The flag to stop the console printer */
     private boolean stop = false;
+
+    /** The file to read */
     private File file;
+
+    /** The console stream */
     private MessageConsoleStream consoleStream;
 
 
+    /**
+     * Creates a new instance of ConsolePrinterThread.
+     *
+     * @param file the file to read
+     * @param consoleStream the console stream
+     */
     public ConsolePrinterThread( File file, MessageConsoleStream consoleStream )
     {
         this.file = file;
@@ -52,21 +68,34 @@ public class ConsolePrinterThread extend
         {
             try
             {
+                // Opening the file reader
                 BufferedReader reader = new BufferedReader( new FileReader( file ) );
-                String line = null;
 
                 while ( !stop )
                 {
-                    line = reader.readLine();
+                    // Checking if the console stream is closed
+                    if ( consoleStream.isClosed() )
+                    {
+                        // We need to exit
+                        break;
+                    }
+                    
+                    // Getting the next line to print
+                    String line = reader.readLine();
+
+                    // Checking the line
                     if ( line != null )
                     {
+                        // Writing the line to the console and moving the next
                         consoleStream.println( line );
                         continue;
                     }
 
+                    // Waiting
                     sleep( 1000 );
                 }
 
+                // Closing the file reader
                 reader.close();
             }
             catch ( FileNotFoundException e )
@@ -79,8 +108,7 @@ public class ConsolePrinterThread extend
             }
             catch ( IOException e )
             {
-                // TODO Auto-generated catch block
-                e.printStackTrace();
+                // Nothing to do
             }
         }
     }



Mime
View raw message