Package uk.ac.bristol.star.cdf
Class DataType
- java.lang.Object
-
- uk.ac.bristol.star.cdf.DataType
-
public abstract class DataType extends java.lang.ObjectEnumerates the data types supported by the CDF format.- Since:
- 20 Jun 2013
-
-
Field Summary
Fields Modifier and Type Field Description static DataTypeBYTEstatic DataTypeCHARstatic DataTypeDOUBLEstatic DataTypeEPOCHstatic DataTypeEPOCH16static DataTypeFLOATstatic DataTypeINT1static DataTypeINT2static DataTypeINT4static DataTypeINT8static DataTypeREAL4static DataTypeREAL8static DataTypeTIME_TT2000static DataTypeUCHARstatic DataTypeUINT1static DataTypeUINT2static DataTypeUINT4
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description java.lang.StringformatArrayValue(java.lang.Object array, int arrayIndex)Provides a string view of an item obtained from an array value of this data type.java.lang.StringformatScalarValue(java.lang.Object value)Provides a string view of a scalar value obtained for this data type.java.lang.Class<?>getArrayElementClass()Returns the element class of an array that this data type can be read into.intgetArrayIndex(int itemIndex)Returns the index into a value array which corresponds to theitem'th element.intgetByteCount()Returns the number of bytes used in a CDF to store a single item of this type.static DataTypegetDataType(int dataType)Returns the DataType object corresponding to a CDF data type code.static DataTypegetDataType(int dataType, CdfInfo cdfInfo)Returns a DataType corresponding to a CDF data type code, possibly customised for a particular CDF file.java.lang.ObjectgetDefaultPadValueArray()Returns an array of array-class values containing a single item with the default pad value for this type.intgetGroupSize()Number of elements of type arrayElementClass that are read into valueArray for a single item read.java.lang.StringgetName()Returns the name for this data type.abstract java.lang.ObjectgetScalar(java.lang.Object valueArray, int arrayIndex)Reads a single item from an array which has previously been populated byreadValues.java.lang.Class<?>getScalarClass()Returns the type of objects obtained by thegetScalarmethod.booleanhasMultipleElementsPerItem()True if this type may turn a variable number of elements from the value array into a single read item.abstract voidreadValues(Buf buf, long offset, int nelPerItem, java.lang.Object valueArray, int count)Reads data of this data type from a buffer into an appropriately typed value array.java.lang.StringtoString()
-
-
-
Field Detail
-
INT1
public static final DataType INT1
-
INT2
public static final DataType INT2
-
INT4
public static final DataType INT4
-
INT8
public static final DataType INT8
-
UINT1
public static final DataType UINT1
-
UINT2
public static final DataType UINT2
-
UINT4
public static final DataType UINT4
-
REAL4
public static final DataType REAL4
-
REAL8
public static final DataType REAL8
-
CHAR
public static final DataType CHAR
-
EPOCH16
public static final DataType EPOCH16
-
BYTE
public static final DataType BYTE
-
FLOAT
public static final DataType FLOAT
-
DOUBLE
public static final DataType DOUBLE
-
EPOCH
public static final DataType EPOCH
-
TIME_TT2000
public static final DataType TIME_TT2000
-
UCHAR
public static final DataType UCHAR
-
-
Method Detail
-
getName
public java.lang.String getName()
Returns the name for this data type.- Returns:
- data type name
-
getByteCount
public int getByteCount()
Returns the number of bytes used in a CDF to store a single item of this type.- Returns:
- size in bytes
-
getArrayElementClass
public java.lang.Class<?> getArrayElementClass()
Returns the element class of an array that this data type can be read into. In most cases this is a primitive type or String.- Returns:
- array raw value element class
-
getScalarClass
public java.lang.Class<?> getScalarClass()
Returns the type of objects obtained by thegetScalarmethod.- Returns:
- scalar type associated with this data type
-
getGroupSize
public int getGroupSize()
Number of elements of type arrayElementClass that are read into valueArray for a single item read. This is usually 1, but not, for instance, for EPOCH16.- Returns:
- number of array elements per item
-
getArrayIndex
public int getArrayIndex(int itemIndex)
Returns the index into a value array which corresponds to theitem'th element.- Returns:
itemIndex*groupSize
-
hasMultipleElementsPerItem
public boolean hasMultipleElementsPerItem()
True if this type may turn a variable number of elements from the value array into a single read item. This is usually false, but true for character types, which turn into strings.- Returns:
- true iff type may have multiple elements per read item
-
getDefaultPadValueArray
public java.lang.Object getDefaultPadValueArray()
Returns an array of array-class values containing a single item with the default pad value for this type.- Returns:
- default raw pad value array
- See Also:
- "Section 2.3.20 of CDF User's Guide"
-
readValues
public abstract void readValues(Buf buf, long offset, int nelPerItem, java.lang.Object valueArray, int count) throws java.io.IOException
Reads data of this data type from a buffer into an appropriately typed value array.- Parameters:
buf- data bufferoffset- byte offset into buffer at which data startsnelPerItem- number of elements per item; usually 1, but may not be for stringsvalueArray- array to receive result datacount- number of items to read- Throws:
java.io.IOException
-
getScalar
public abstract java.lang.Object getScalar(java.lang.Object valueArray, int arrayIndex)Reads a single item from an array which has previously been populated byreadValues. The class of the returned value is that returned bygetScalarClass().The
arrayIndexargument is the index into the array object, not necessarily the item index - see thegetArrayIndexmethod.- Parameters:
valueArray- array filled with data for this data typearrayIndex- index into array at which the item to read is found- Returns:
- scalar representation of object at position
indexinvalueArray
-
formatScalarValue
public java.lang.String formatScalarValue(java.lang.Object value)
Provides a string view of a scalar value obtained for this data type.- Parameters:
value- value returned bygetScalar- Returns:
- string representation
-
formatArrayValue
public java.lang.String formatArrayValue(java.lang.Object array, int arrayIndex)Provides a string view of an item obtained from an array value of this data type.The
arrayIndexargument is the index into the array object, not necessarily the item index - see thegetArrayIndexmethod.- Parameters:
array- array value populated byreadValuesarrayIndex- index into array- Returns:
- string representation
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
getDataType
public static DataType getDataType(int dataType, CdfInfo cdfInfo) throws CdfFormatException
Returns a DataType corresponding to a CDF data type code, possibly customised for a particular CDF file.Currently, this returns the same as
getDataType(int), except for TIME_TT2000 columns, in which case the last known leap second may be taken into account.- Parameters:
dataType- dataType field of AEDR or VDRcdfInfo- specifics of CDF file- Returns:
- data type object
- Throws:
CdfFormatException
-
getDataType
public static DataType getDataType(int dataType) throws CdfFormatException
Returns the DataType object corresponding to a CDF data type code.- Parameters:
dataType- dataType field of AEDR or VDR- Returns:
- data type object
- Throws:
CdfFormatException
-
-