annotate src/samer/units/DoubleWriter.java @ 8:5e3cbbf173aa tip

Reorganise some more
author samer
date Fri, 05 Apr 2019 22:41:58 +0100
parents bf79fb79ee13
children
rev   line source
samer@0 1 //
samer@0 2 // DoubleWriter.java
samer@0 3 //
samer@0 4 //
samer@0 5 // Created by Samer Abdallah on Mon Jun 10 2002.
samer@0 6 // Copyright (c) 2002 __MyCompanyName__. All rights reserved.
samer@0 7 //
samer@0 8
samer@0 9 package samer.units;
samer@0 10
samer@0 11 import samer.core.*;
samer@0 12 import samer.core.types.*;
samer@0 13 import samer.tools.*;
samer@0 14 import samer.maths.*;
samer@0 15 import java.io.*;
samer@0 16
samer@0 17 /**
samer@0 18 Write sequence of doubles to a stream as text
samer@0 19 */
samer@0 20
samer@0 21 public class DoubleWriter extends AnonymousTask {
samer@0 22 DoubleModel x; // data to send
samer@0 23 OutputStream out; // stream to write to
samer@0 24 PrintStream prn;
samer@0 25
samer@0 26 public DoubleWriter(DoubleModel x, OutputStream out) throws Exception { this(x,out,true); }
samer@0 27 public DoubleWriter(DoubleModel x, OutputStream out, boolean autoflush) throws Exception
samer@0 28 {
samer@0 29 this.x=x;
samer@0 30 this.out=out;
samer@0 31 prn=new PrintStream(out,autoflush); // autoflush or not?
samer@0 32 }
samer@0 33
samer@0 34 public void dispose() {
samer@0 35 try {
samer@0 36 prn.flush();
samer@0 37 prn.close();
samer@0 38 } catch (Exception ex) {}
samer@0 39 // close out?
samer@0 40 }
samer@0 41
samer@0 42 public Task getTask() { return this; }
samer@0 43
samer@0 44 public void run() throws Exception {
samer@0 45 prn.println(x.get());
samer@0 46 // how often should we flush?
samer@0 47 }
samer@0 48 public void stopping() {
samer@0 49 try { prn.flush(); }
samer@0 50 catch (Exception ex) {}
samer@0 51 }
samer@0 52 }