FileDocCategorySizeDatePackage
FileOutput.javaAPI DocGlassfish v2 API3933Fri May 04 22:31:06 BST 2007com.sun.appserv.management.util.misc

FileOutput

public final class FileOutput extends Object implements Output
Directs output to a file. Lazy initialization; the file is not actually opened until output is sent.

Fields Summary
private PrintStream
mOut
private final File
mFile
private final boolean
mAppend
Constructors Summary
public FileOutput(File f)

	    this( f, false );
	
public FileOutput(File f, boolean append)

	    mOut    = null;
	    mFile   = f;
	    mAppend = append;
	
Methods Summary
public voidclose()

	    if ( mOut != null )
	    {
    	    try
    	    {
    	        mOut.close();
    	    }
    	    finally
    	    {
    	        mOut    = null;
    	    }
	    }
	
public booleangetDebug()

	    lazyInit();
		return( false );
	
private voidlazyInit()

	    if ( mOut == null ) synchronized( this )
	    {
    	    if ( mOut == null )
    	    {
    	        try
    	        {
                    if ( (! mAppend) && mFile.exists() )
                    {
                        mFile.delete();
                    }
                
    	            mOut    = new PrintStream( new FileOutputStream( mFile, mAppend) );
    	        }
    	        catch( Exception e )
    	        {
    	            // don't use System.out/err; possible infinite recursion
    	            throw new RuntimeException( "Can't create file: " + mFile +
    	                ", exception = " + e );
    	        }
    	    }
    	}
	
public voidprint(java.lang.Object o)

	    lazyInit();
	    mOut.print( o.toString() );
	
public voidprintDebug(java.lang.Object o)

	    lazyInit();
	    println( "DEBUG: " + o );
	
public voidprintError(java.lang.Object o)

	    lazyInit();
	    println( "ERROR: " + o );
	
public voidprintln(java.lang.Object o)

	    lazyInit();
	    mOut.println( o.toString() );