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.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.DataSetUtil; import org.das2.qds.QDataSet; import org.das2.qds.SemanticOps; import org.das2.qstream.AsciiTimeTransferType; import org.das2.qstream.TransferType; /** * Format to doubles. * @author jbf */ public class BinaryDataFormatter implements DataFormatter { private static final Logger logger= Logger.getLogger("hapi"); TransferType[] transferTypes; ByteBuffer b; int bufferSize; public BinaryDataFormatter( ) { } @Override public void initialize( JSONObject info, OutputStream out, QDataSet record) { try { transferTypes= new TransferType[record.length()]; bufferSize= 0; int totalFields= 0; JSONArray parameters= info.getJSONArray("parameters"); for ( int i=0; i0 && bytes[ipos]<0 ) ipos--; // unicode characters > 127 are multi-byte. buffer.put( bytes, 0, ipos ); //TODO: we could be in the middle of a UTF-8 letter. } } @Override public double read(ByteBuffer buffer) { throw new UnsupportedOperationException("Not supported."); } @Override public int sizeBytes() { return len; } @Override public boolean isAscii() { return false; } @Override public String name() { return "string"+len; } }; } else if ( stype.equals("double") || stype.equals("integer")) { tt= TransferType.getForName(stype, Collections.singletonMap(QDataSet.UNITS,(Object)u) ); } else { throw new IllegalArgumentException("server is misconfigured, using unsupported type: "+stype ); } int nfields; if ( parameter.has("size") ) { JSONArray ja= (JSONArray)parameter.get("size"); int prod= 1; for ( int j=0; j