samer@0: // samer@0: // DoubleWriter.java samer@0: // samer@0: // samer@0: // Created by Samer Abdallah on Mon Jun 10 2002. samer@0: // Copyright (c) 2002 __MyCompanyName__. All rights reserved. samer@0: // samer@0: samer@0: package samer.units; samer@0: samer@0: import samer.core.*; samer@0: import samer.core.types.*; samer@0: import samer.tools.*; samer@0: import samer.maths.*; samer@0: import java.io.*; samer@0: samer@0: /** samer@0: Write sequence of doubles to a stream as text samer@0: */ samer@0: samer@0: public class DoubleWriter extends AnonymousTask { samer@0: DoubleModel x; // data to send samer@0: OutputStream out; // stream to write to samer@0: PrintStream prn; samer@0: samer@0: public DoubleWriter(DoubleModel x, OutputStream out) throws Exception { this(x,out,true); } samer@0: public DoubleWriter(DoubleModel x, OutputStream out, boolean autoflush) throws Exception samer@0: { samer@0: this.x=x; samer@0: this.out=out; samer@0: prn=new PrintStream(out,autoflush); // autoflush or not? samer@0: } samer@0: samer@0: public void dispose() { samer@0: try { samer@0: prn.flush(); samer@0: prn.close(); samer@0: } catch (Exception ex) {} samer@0: // close out? samer@0: } samer@0: samer@0: public Task getTask() { return this; } samer@0: samer@0: public void run() throws Exception { samer@0: prn.println(x.get()); samer@0: // how often should we flush? samer@0: } samer@0: public void stopping() { samer@0: try { prn.flush(); } samer@0: catch (Exception ex) {} samer@0: } samer@0: }