package org.autoplot.hapiserver; import java.io.IOException; import java.io.OutputStream; import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.nio.charset.Charset; import java.util.Collections; import java.util.logging.ConsoleHandler; import java.util.logging.Level; import java.util.logging.Logger; import org.das2.datum.Units; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import org.das2.qds.QDataSet; import org.das2.qds.SemanticOps; import org.das2.qds.ops.Ops; import org.das2.qstream.AsciiTimeTransferType; import org.das2.qstream.TransferType; /** * Format to binary types. Note that TransferTypes use doubles to communicate, * so floating point numbers may not format precisely. * @author jbf */ public class BinaryDataFormatter implements DataFormatter { private static final Logger logger= Logger.getLogger("hapi"); TransferType[] transferTypes; double[] fill; ByteBuffer b; int bufferSize; int sentRecordCount; public BinaryDataFormatter( ) { } @Override public void initialize( JSONObject info, OutputStream out, QDataSet record) { try { transferTypes= new TransferType[record.length()]; fill= new double[record.length()]; bufferSize= 0; int totalFields= 0; JSONArray parameters= info.getJSONArray("parameters"); for ( int i=0; i0 && Ops.valid(d).value()==0 ) { transferTypes[i].write( fill[i], b ); } else { transferTypes[i].write( d.value(), b ); } } byte[] bytes= b.array(); if ( sentRecordCount==0 ) { if ( logger.isLoggable(Level.FINE) ) { StringBuilder sbuf; sbuf = new StringBuilder(); int nf= Math.min(80,bytes.length); for ( int i=0; i