Class CdfReader

java.lang.Object
uk.ac.bristol.star.cdf.CdfReader

public class CdfReader extends Object
Examines a CDF file and provides methods to access its records.

Constructing an instance of this class reads enough of a file to identify it as a CDF and work out how to access its records. Most of the actual contents are only read from the data buffer as required. Although only the magic numbers and CDR are read during construction, in the case of a file-compressed CDF the whole thing is uncompressed, so it could still be an expensive operation.

For low-level access to the CDF internal records, use the getCdr() method to get the CdfDescriptorRecord and use that in conjunction with knowledge of the internal format of CDF files as a starting point to chase pointers around the file constructing other records. When you have a pointer to another record, you can use the record factory got from getRecordFactory() to turn it into a typed Record object.

Since:
19 Jun 2013
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs a CdfReader from a readable file containing its byte data.
    Constructs a CdfReader from a buffer containing its byte data.
  • Method Summary

    Modifier and Type
    Method
    Description
    Returns the buffer containing the uncompressed record stream for this reader's CDF file.
    Returns the CDF Descriptor Record object for this reader's CDF.
    Returns a RecordFactory that can be applied to this reader's Buf to construct CDF Record objects.
    static boolean
    isMagic(byte[] intro)
    Examines a byte array to see if it looks like the start of a CDF file.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • CdfReader

      public CdfReader(Buf buf) throws IOException
      Constructs a CdfReader from a buffer containing its byte data.
      Parameters:
      buf - buffer containing CDF file
      Throws:
      IOException
    • CdfReader

      public CdfReader(File file) throws IOException
      Constructs a CdfReader from a readable file containing its byte data.
      Parameters:
      file - CDF file
      Throws:
      IOException
  • Method Details

    • getBuf

      public Buf getBuf()
      Returns the buffer containing the uncompressed record stream for this reader's CDF file. This will be the buffer originally submitted at construction time only if the CDF does not use whole-file compression.
      Returns:
      buffer containing CDF records
    • getRecordFactory

      public RecordFactory getRecordFactory()
      Returns a RecordFactory that can be applied to this reader's Buf to construct CDF Record objects.
      Returns:
      record factory
    • getCdr

      public CdfDescriptorRecord getCdr()
      Returns the CDF Descriptor Record object for this reader's CDF.
      Returns:
      CDF Descriptor Record
    • isMagic

      public static boolean isMagic(byte[] intro)
      Examines a byte array to see if it looks like the start of a CDF file.
      Parameters:
      intro - byte array, at least 8 bytes if available
      Returns:
      true iff the first 8 bytes of intro are a CDF magic number