uk.ac.starlink.pds4.FieldReader Maven / Gradle / Ivy
package uk.ac.starlink.pds4;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Function;
import java.util.function.DoubleFunction;
import java.util.function.DoubleUnaryOperator;
import java.util.function.IntFunction;
import java.util.function.LongFunction;
import java.util.function.UnaryOperator;
import java.util.logging.Logger;
import gov.nasa.pds.label.object.FieldType;
import gov.nasa.pds.objectAccess.table.FieldAdapter;
import uk.ac.starlink.util.DoubleList;
import uk.ac.starlink.util.FloatList;
import uk.ac.starlink.util.IntList;
import uk.ac.starlink.util.LongList;
import uk.ac.starlink.util.ShortList;
/**
* Adapts a FieldAdapter to return a typed value.
* The NASA-provided FieldAdapter class does the work of reading bytes
* or text to turn them into some numeric or string value,
* but this class augments that to provide an object that knows what
* type of object should be read.
* An instance of this class may be used to read either scalar values
* or (within a Field_Group_*) array values.
*
* @author Mark Taylor
* @since 24 Nov 2021
*/
public abstract class FieldReader {
private final FieldType ftype_;
private final FieldAdapter adapter_;
private final Class scalarClazz_;
private final Class arrayClazz_;
private static final Logger logger_ =
Logger.getLogger( "uk.ac.starlink.pds4" );
/**
* Constructor.
*
* @param ftype field type
* @param scalarClazz field data content class for scalar values
* @param arrayClazz field data content class for array values
*/
private FieldReader( FieldType ftype,
Class scalarClazz, Class arrayClazz ) {
ftype_ = ftype;
adapter_ = ftype.getAdapter();
scalarClazz_ = scalarClazz;
arrayClazz_ = arrayClazz;
}
/**
* Reads a typed scalar value from a buffer in accordance
* with this field type.
*
* The startBit and endBit arguments reflect their appearence in
* the corresponding NASA classes, but I don't know what they do.
*
* @param buf byte buffer containing data
* @param offset index into buf of byte at which data value begins
* @param length number of bytes over which value is represented
* @param startBit ??
* @param endBit ??
* @return typed data value
*/
public abstract S readScalar( byte[] buf, int offset, int length,
int startBit, int endBit );
/**
* Reads an value from a buffer in accordance with this field type
* and stores it in one element of a supplied typed array.
* There is a limit to what null handling can be done in this case.
*
*