view dwt/dwthelper/FileOutputStream.d @ 330:f980ea238e72

it is possible for "this.istr" to be null before this method is called, so we should check for it before attempting to close the stream
author Craig Slusher <cslush@gmail.com>
date Mon, 26 Jan 2009 10:46:51 -0500
parents 8d53428f9be0
children 1ee938a6e02e
line wrap: on
line source

/**
 * Authors: Frank Benoit <keinfarbton@googlemail.com>
 */
module dwt.dwthelper.FileOutputStream;

public import dwt.dwthelper.File;
public import dwt.dwthelper.OutputStream;

import dwt.dwthelper.utils;

version(TANGOSVN){
import tango.io.device.FileConduit;
} else {
import tango.io.FileConduit;
}

public class FileOutputStream : dwt.dwthelper.OutputStream.OutputStream {

    alias dwt.dwthelper.OutputStream.OutputStream.write write;
    alias dwt.dwthelper.OutputStream.OutputStream.close close;
    FileConduit fc;
    
    public this ( String name ){
        fc = new FileConduit( name, FileConduit.WriteCreate );
    }

    public this ( String name, bool append ){
        fc = new FileConduit( name, append ? FileConduit.WriteAppending : FileConduit.WriteCreate );
    }

    public this ( dwt.dwthelper.File.File file ){
        this( file.toString );
    }

    public this ( dwt.dwthelper.File.File file, bool append ){
        this( file.toString, append );
    }

    public override void write( int b ){
        ubyte[1] a;
        a[0] = b & 0xFF;
        fc.write(a);
    }

    public override void close(){
        fc.close();
    }

    public void finalize(){
        implMissing( __FILE__, __LINE__ );
    }


}