comparison src/samer/units/DoubleWriter.java @ 0:bf79fb79ee13

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