Package nom.tam.fits

Class Data

java.lang.Object
nom.tam.fits.Data
All Implemented Interfaces:
FitsElement
Direct Known Subclasses:
AbstractTableData, ImageData, RandomGroupsData, UndefinedData

public abstract class Data extends Object implements FitsElement
The data segment of an HDU.

This is the object which contains the actual data for the HDU.

  • For images and primary data this is a simple (but possibly multi-dimensional) primitive array. When group data is supported it will be a possibly multidimensional array of group objects.
  • For ASCII data it is a two dimensional Object array where each of the constituent objects is a primitive array of length 1.
  • For Binary data it is a two dimensional Object array where each of the constituent objects is a primitive array of arbitrary (more or less) dimensionality.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    long
    Computes and returns the FITS checksum for this data, for example to compare against the stored DATASUM in the FITS header (e.g. via BasicHDU.getStoredDatasum()).
    void
    Detaches this data object from the input (if any), such as a file or stream, but not before loading data from the previously assigned input into memory.
    Returns the underlying Java representation of the data contained in this HDU's data segment.
    long
    Returns the byte offset at which this element starts ina file.
    final Object
    Same as getData().
    long
    Returns the size of this elements in the FITS representation.
    boolean
    Checks if the data should be assumed to be in deferred read mode.
    boolean
    Checks if the data content is currently empty, i.e. no actual data is currently stored in memory.
    void
    Reads the data or skips over it for reading later, depending on whether reading from a stream or a random acessible input, respectively.
    boolean
    Reset the input stream to point to the beginning of this element
    void
    Rewrite the contents of the element in place.
    boolean
    Checks if we can write this element back to its source.
    abstract BasicHDU<?>
    Returns an approprotae HDU object that encapsulates this FITS data, and contains the minimal mandatory header description for that data.
    abstract void
    Writes the contents of the element to a data sink, adding padding as necessary if the element (such as a header or data segment) is expected to complete the FITS block of 2880 bytes.

    Methods inherited from class java.lang.Object

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

    • Data

      public Data()
  • Method Details

    • isDeferred

      public boolean isDeferred()
      Checks if the data should be assumed to be in deferred read mode.
      Returns:
      true if it is set for deferred reading at a later time, or else false if this data is currently loaded into RAM. #see detach()
      Since:
      1.17
    • isEmpty

      public boolean isEmpty()
      Checks if the data content is currently empty, i.e. no actual data is currently stored in memory.
      Returns:
      true if there is no actual data in memory, otherwise false
      Since:
      1.18
      See Also:
    • calcChecksum

      public long calcChecksum() throws FitsException
      Computes and returns the FITS checksum for this data, for example to compare against the stored DATASUM in the FITS header (e.g. via BasicHDU.getStoredDatasum()). This method always computes the checksum from data in memory. As such it will fully load deferred read mode data into RAM to perform the calculation, and use the standard padding to complete the FITS block for the calculation. As such the checksum may differ from that of the file if the file uses a non-standard padding. Hence, for verifying data integrity as stored in a file BasicHDU.verifyDataIntegrity() or BasicHDU.verifyIntegrity() should be preferred.
      Returns:
      the computed FITS checksum from the data (fully loaded in memory).
      Throws:
      FitsException - if there was an error while calculating the checksum
      Since:
      1.17
      See Also:
    • getData

      public Object getData() throws FitsException
      Returns the underlying Java representation of the data contained in this HDU's data segment. Typically it will return a Java array of some kind.
      Returns:
      the underlying Java representation of the data core object, such as a multi-dimensional Java array.
      Throws:
      FitsException - if the data could not be gathered.
      See Also:
    • getFileOffset

      public long getFileOffset()
      Description copied from interface: FitsElement
      Returns the byte offset at which this element starts ina file. If the element was not obtained from an input, then 0 is returned.
      Specified by:
      getFileOffset in interface FitsElement
      Returns:
      the byte at which this element begins. This is only available if the data is originally read from a random access medium. Otherwise 0 is returned.
    • getKernel

      public final Object getKernel() throws FitsException
      Same as getData().
      Returns:
      The data content as represented by a Java object..
      Throws:
      FitsException - if the data could not be gathered .
    • getSize

      public long getSize()
      Description copied from interface: FitsElement
      Returns the size of this elements in the FITS representation. This may include padding if the element (such as a header or data segment) is expected to complete a FITS block of 2880 bytes.
      Specified by:
      getSize in interface FitsElement
      Returns:
      The size of this element in bytes, or 0 if the element is empty or invalid.
    • read

      public void read(ArrayDataInput in) throws PaddingException, FitsException

      Reads the data or skips over it for reading later, depending on whether reading from a stream or a random acessible input, respectively.

      In case the argument is a an instance of RandomAccess input (such as a FitsFile, the call will simply note where in the file the data segment can be found for reading at a later point, only when the data content is accessed. This 'deferred' reading behavior make it possible to process large HDUs even with small amount of RAM, and can result in a significant performance boost when inspectring large FITS files, or using only select content from large FITS files.

      Specified by:
      read in interface FitsElement
      Parameters:
      in - The input data stream
      Throws:
      PaddingException - if there is missing padding between the end of the data segment and the enf-of-file.
      FitsException - if the data appears to be corrupted.
      See Also:
    • reset

      public boolean reset()
      Description copied from interface: FitsElement
      Reset the input stream to point to the beginning of this element
      Specified by:
      reset in interface FitsElement
      Returns:
      True if the reset succeeded.
    • rewrite

      public void rewrite() throws FitsException
      Description copied from interface: FitsElement
      Rewrite the contents of the element in place. The data must have been originally read from a random access device, and the size of the element may not have changed.
      Specified by:
      rewrite in interface FitsElement
      Throws:
      FitsException - if the rewrite was unsuccessful.
    • rewriteable

      public boolean rewriteable()
      Description copied from interface: FitsElement
      Checks if we can write this element back to its source. An element can only be written back if it is associated to a random accessible input and the current size FITS within the old block size.
      Specified by:
      rewriteable in interface FitsElement
      Returns:
      true if this element can be rewritten?
    • detach

      public void detach() throws FitsException
      Detaches this data object from the input (if any), such as a file or stream, but not before loading data from the previously assigned input into memory.
      Throws:
      FitsException - if there was an issue loading the data from the previous input (if any)
      Since:
      1.18
      See Also:
    • write

      public abstract void write(ArrayDataOutput o) throws FitsException
      Description copied from interface: FitsElement
      Writes the contents of the element to a data sink, adding padding as necessary if the element (such as a header or data segment) is expected to complete the FITS block of 2880 bytes.
      Specified by:
      write in interface FitsElement
      Parameters:
      o - The data sink.
      Throws:
      FitsException - if the write was unsuccessful.
    • toHDU

      public abstract BasicHDU<?> toHDU() throws FitsException
      Returns an approprotae HDU object that encapsulates this FITS data, and contains the minimal mandatory header description for that data.
      Returns:
      a HDU object ocntaining the data and its minimal required header description
      Throws:
      FitsException - If the data cannot be converted to an HDU for some reason.