view 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
line wrap: on
line source
//
//  DoubleWriter.java
//  
//
//  Created by Samer Abdallah on Mon Jun 10 2002.
//  Copyright (c) 2002 __MyCompanyName__. All rights reserved.
//

package samer.units;

import samer.core.*;
import samer.core.types.*;
import samer.tools.*;
import samer.maths.*;
import java.io.*;

/**
	Write sequence of doubles to a stream as text
 */

public class DoubleWriter extends AnonymousTask {
	DoubleModel	x;		// data to send
	OutputStream	out;	// stream to write to
	PrintStream		prn;

	public DoubleWriter(DoubleModel x, OutputStream out) throws Exception { this(x,out,true); }
	public DoubleWriter(DoubleModel x, OutputStream out, boolean autoflush) throws Exception
	{
		this.x=x;
		this.out=out;
		prn=new PrintStream(out,autoflush); // autoflush or not?
	}

	public void dispose() {
		try {
			prn.flush();
			prn.close();
		} catch (Exception ex) {}
		// close out?
	}

	public Task getTask() { return this; }
	
	public void run()  throws Exception {
		prn.println(x.get());
		// how often should we flush?
	}
	public void stopping() {
		try { prn.flush(); }
		catch (Exception ex) {}
	}
}