Ignore:
Timestamp:
10/10/11 22:15:34 (13 years ago)
Author:
sherbold
Message:
  • various changed to de.ugoe.cs.util.Console:
    • changed instantiation method of the instance, i.e., how the Singleton property is guaranteed
    • added method reset() to remove all listeners at once
    • added functions to check is a given listener is registered
  • various changes to de.ugoe.cs.util.FileOutputListener?:
    • added null-checks for writer to improve behavior in case of improper usage
    • added method getFilename() to check to which file the listener writes.
  • added method setDebug() to de.ugoe.cs.util.TextConsole? to define whether trace stream is displayed or not.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaHelperLib/src/de/ugoe/cs/util/console/FileOutputListener.java

    r243 r250  
    3939         * </p> 
    4040         */ 
    41         FileWriter writer; 
     41        FileWriter writer = null; 
    4242 
    4343        /** 
     
    7878        public void stop() { 
    7979                Console.getInstance().removeOutputListener(this); 
    80                 try { 
    81                         writer.close(); 
    82                 } catch (IOException e) { 
    83                         Console.printerrln("Failed to close file " + filename + ": " 
    84                                         + e.getMessage()); 
     80                if( writer!=null ) { 
     81                        try { 
     82                                writer.close(); 
     83                                writer = null; 
     84                        } catch (IOException e) { 
     85                                Console.printerrln("Failed to close file " + filename + ": " 
     86                                                + e.getMessage()); 
     87                        } 
    8588                } 
    8689        } 
     
    9598        @Override 
    9699        public void outputMsg(String newMessage) { 
    97                 try { 
    98                         writer.write(newMessage); 
    99                 } catch (IOException e) { 
    100                         if (!failureLogged) { 
    101                                 Console.printerrln("FileOutpustListener for file " + filename 
    102                                                 + " broken: " + e.getMessage()); 
    103                                 failureLogged = true; 
     100                if( writer!=null ) { 
     101                        try { 
     102                                writer.write(newMessage); 
     103                        } catch (IOException e) { 
     104                                if (!failureLogged) { 
     105                                        Console.printerrln("FileOutpustListener for file " + filename 
     106                                                        + " broken: " + e.getMessage()); 
     107                                        failureLogged = true; 
     108                                } 
    104109                        } 
    105110                } 
    106111        } 
    107112 
     113        /** 
     114         * <p> 
     115         * Returns the name of the log file used by this listener. 
     116         * </p> 
     117         *  
     118         * @return name of the log file 
     119         */ 
     120        public String getFilename() { 
     121                return filename; 
     122        } 
     123 
    108124} 
Note: See TracChangeset for help on using the changeset viewer.