uk.ac.bristol.star.cdf.record
Class Record

java.lang.Object
  extended by uk.ac.bristol.star.cdf.record.Record
Direct Known Subclasses:
AttributeDescriptorRecord, AttributeEntryDescriptorRecord, CdfDescriptorRecord, CompressedCdfRecord, CompressedParametersRecord, CompressedVariableValuesRecord, GlobalDescriptorRecord, SparsenessParametersRecord, UnusedInternalRecord, VariableDescriptorRecord, VariableIndexRecord, VariableValuesRecord

public abstract class Record
extends java.lang.Object

Abstract superclass for a CDF Record object. A Record represents one of the sequence of typed records of which a CDF file is composed.

Since:
18 Jun 2013

Constructor Summary
protected Record(RecordPlan plan, java.lang.String abbrev)
          Constructs a record with no known record type.
protected Record(RecordPlan plan, java.lang.String abbrev, int fixedType)
          Constructs a record with a known record type.
 
Method Summary
protected  void checkEndRecord(Pointer ptr)
          Checks that a pointer is positioned at the end of this record.
protected  int checkIntValue(int actualValue, int fixedValue)
          Checks that an integer has a known fixed value.
 Buf getBuf()
          Returns the buffer containing the record data.
 long getContentOffset()
          Returns the buffer offset of the first field in this record after the record size and type values.
 long getRecordSize()
          Returns the size of the record in bytes.
 int getRecordType()
          Returns the type code identifying what kind of CDF record it is.
 java.lang.String getRecordTypeAbbreviation()
          Returns the abbreviated form of the record type for this record.
static boolean hasBit(int flags, int ibit)
          Indicates whether a given bit of a flags mask is set.
static int[] readIntArray(Buf buf, Pointer ptr, int count)
          Reads a moderately-sized array of 4-byte big-endian integers.
static long[] readOffsetArray(Buf buf, Pointer ptr, int count)
          Reads a moderately-sized offset 8-byte big-endian integers.
static java.lang.String[] toLines(java.lang.String text)
          Splits an ASCII string into 0x0A-terminated lines.
protected  void warnFormat(java.lang.String msg)
          Called by check* methods to issue a warning if the check has failed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Record

protected Record(RecordPlan plan,
                 java.lang.String abbrev)
Constructs a record with no known record type.

Parameters:
plan - basic record information
abbrev - abreviated name for record type

Record

protected Record(RecordPlan plan,
                 java.lang.String abbrev,
                 int fixedType)
Constructs a record with a known record type.

Parameters:
plan - basic record information
abbrev - abreviated name for record type
fixedType - record type asserted for this record
Method Detail

getRecordSize

public long getRecordSize()
Returns the size of the record in bytes.

Returns:
record size

getRecordType

public int getRecordType()
Returns the type code identifying what kind of CDF record it is.

Returns:
record type

getBuf

public Buf getBuf()
Returns the buffer containing the record data.

Returns:
buffer

getRecordTypeAbbreviation

public java.lang.String getRecordTypeAbbreviation()
Returns the abbreviated form of the record type for this record.

Returns:
record type abbreviation

getContentOffset

public long getContentOffset()
Returns the buffer offset of the first field in this record after the record size and type values.

Returns:
buffer offset for non-generic record content

checkIntValue

protected int checkIntValue(int actualValue,
                            int fixedValue)
Checks that an integer has a known fixed value. If not, a warning may be emitted. This performs an assertion-like function. The actual value is returned as a convenience.

Parameters:
actualValue - value to test
fixedValue - value to compare against
Returns:
actualValue

checkEndRecord

protected void checkEndRecord(Pointer ptr)
Checks that a pointer is positioned at the end of this record. If not, a warning may be emitted. This performs an assertion-like function. This can be called by code which thinks it has read a whole record's content to check that it's got the counting right.

Parameters:
ptr - pointer notionally positioned at end of record

warnFormat

protected void warnFormat(java.lang.String msg)
Called by check* methods to issue a warning if the check has failed.

Parameters:
msg - message to output

readIntArray

public static int[] readIntArray(Buf buf,
                                 Pointer ptr,
                                 int count)
                          throws java.io.IOException
Reads a moderately-sized array of 4-byte big-endian integers. Pointer position is moved on appropriately. Not intended for potentially very large arrays.

Parameters:
buf - buffer
ptr - pointer
count - number of values to read
Returns:
count-element array of values
Throws:
java.io.IOException

readOffsetArray

public static long[] readOffsetArray(Buf buf,
                                     Pointer ptr,
                                     int count)
                              throws java.io.IOException
Reads a moderately-sized offset 8-byte big-endian integers. Pointer position is moved on appropriately. Not intended for potentially very large arrays.

Parameters:
buf - buffer
ptr - pointer
count - number of values to read
Returns:
count-element array of values
Throws:
java.io.IOException

toLines

public static java.lang.String[] toLines(java.lang.String text)
Splits an ASCII string into 0x0A-terminated lines.

Parameters:
text - string containing ASCII characters
Returns:
array of lines split on linefeeds

hasBit

public static boolean hasBit(int flags,
                             int ibit)
Indicates whether a given bit of a flags mask is set.

Parameters:
flags - flags mask
ibit - bit index; 0 is the least significant