1 23 package com.sun.appserv.management.util.misc; 24 25 import java.io.File ; 26 import java.io.FileOutputStream ; 27 import java.io.PrintStream ; 28 import java.io.FileNotFoundException ; 29 30 34 public final class FileOutput implements Output 35 { 36 private PrintStream mOut; 37 private final File mFile; 38 private final boolean mAppend; 39 40 public 41 FileOutput( final File f ) 42 { 43 this( f, false ); 44 } 45 46 public 47 FileOutput( final File f, boolean append ) 48 { 49 mOut = null; 50 mFile = f; 51 mAppend = append; 52 } 53 54 private void 55 lazyInit() 56 { 57 if ( mOut == null ) synchronized( this ) 58 { 59 if ( mOut == null ) 60 { 61 try 62 { 63 mOut = new PrintStream ( new FileOutputStream ( mFile, mAppend) ); 64 } 65 catch( Exception e ) 66 { 67 throw new RuntimeException ( "Can't create file: " + mFile + 69 ", exception = " + e ); 70 } 71 } 72 } 73 } 74 75 public void 76 print( final Object o ) 77 { 78 lazyInit(); 79 mOut.print( o.toString() ); 80 } 81 82 public void 83 println( Object o ) 84 { 85 lazyInit(); 86 mOut.println( o.toString() ); 87 } 88 89 public void 90 printError( final Object o ) 91 { 92 lazyInit(); 93 println( "ERROR: " + o ); 94 } 95 96 public boolean 97 getDebug() 98 { 99 lazyInit(); 100 return( false ); 101 } 102 103 public void 104 printDebug( final Object o ) 105 { 106 lazyInit(); 107 println( "DEBUG: " + o ); 108 } 109 110 111 public void 112 close( ) 113 { 114 if ( mOut != null ) 115 { 116 try 117 { 118 mOut.close(); 119 } 120 finally 121 { 122 mOut = null; 123 } 124 } 125 } 126 }; 127 128 129 | Popular Tags |