Mercurial > hg > jslab
view src/samer/units/VecToStream.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
// // VecToStream.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.tools.*; import samer.maths.*; import java.io.*; /** Write sequence of vectors to stream in binary format. */ public class VecToStream extends AnonymousTask { Vec x; // the vector itself OutputStream out; // stream to write to DataOutputStream objout; Task task; public VecToStream(Vec x, OutputStream out) throws Exception { this.x=x; this.out=out; objout=new DataOutputStream(out); double [] a=x.array(); //if (a!=null) task=new ArrayObjectWriter(a); //else task=new IteratorFloatWriter(); } public void dispose() { try { objout.flush(); objout.close(); } catch (Exception ex) {} // close out? } public Task getTask() { return task; } public void run() throws Exception { task.run(); /* autoflush? */ } public void stopping() { try { objout.flush(); } catch (Exception ex) {} } class ArrayObjectWriter extends AnonymousTask { double [] array; public ArrayObjectWriter(double [] a) { array=a; } public void run() throws Exception { // objout.writeObject(array); } } class IteratorFloatWriter extends AnonymousTask { public void run() throws Exception { Vec.Iterator i=x.iterator(); while (i.more()) { objout.writeFloat((float)i.next()); } } } }