eap.fits
Class FitsData

java.lang.Object
  extended byeap.fits.FitsData
Direct Known Subclasses:
FitsImageData, FitsTableData

public class FitsData
extends Object

Represents the data part of a FITS HDU. The data are stored internally as a byte array, and this class provides I/O streams for reading and writing formatted data in that array. This way the user has random access to the data, but does not need to parse the entire HDU if they are only interested in a small part of it. The problem with this approach is that it can require a large amount of memory, and it may be impossible to read particularly large FITS files. At some point I should modify this class to keep the raw storage on disk. However, there are many uses (e.g. in an Applet), where you may not be allowed to write to a local disk, so I'm not sure how useful that would be in practice.

This class does not understand the structure of the data. Therefore this class is amost never instantiated. Instead, you should typically use FitsImageData or FitsBinTableData.


Field Summary
protected  byte[] data
          the internal data array
protected  DataInputStream interpreter
          used for reading formatted data from the internal data array
protected  boolean isComplete
          flag indicating if all the data bytes have been read
static int PADDING
          value to use when padding out partial blocks.
protected  DataOutputStream setter
          for writing formatted values into the internal data array
protected  int valid_bytes
          the number of bytes which have been read from a data source
 
Constructor Summary
FitsData(FitsHeader header)
          Create a data object with the correct size for the given header.
FitsData(int size)
          Creates a data object with the internal data array initialized to hold the given number of bytes.
 
Method Summary
protected  int available()
          returns the number of bytes remaining in the raw data array between the current position and the end of the array.
 int blockCount()
          returns the number of blocks (including partial blocks) in the data
static FitsData createFrom(FitsHeader header)
          This is a factory method to produce a FitsData object of the appropriate type corresponding to a given header
protected  byte[] data()
          returns the raw data array
 void goToByte(long new_position)
          reposition the data reader and writer streams to a given offset in the raw data array.
 void incrementValidBytes(int new_bytes)
          adjust the number of valid bytes by a given increment.
 boolean isComplete()
          returns true if the data array has been completely read.
 void setValidBytes(int valid_bytes)
          update the number of bytes which have been set in the data array.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PADDING

public static final int PADDING
value to use when padding out partial blocks. This is zero according to the FITS standard

See Also:
Constant Field Values

data

protected byte[] data
the internal data array


valid_bytes

protected int valid_bytes
the number of bytes which have been read from a data source


isComplete

protected boolean isComplete
flag indicating if all the data bytes have been read


interpreter

protected DataInputStream interpreter
used for reading formatted data from the internal data array


setter

protected DataOutputStream setter
for writing formatted values into the internal data array

Constructor Detail

FitsData

public FitsData(int size)
Creates a data object with the internal data array initialized to hold the given number of bytes.

Parameters:
size - the number of bytes in the data, not including padding.

FitsData

public FitsData(FitsHeader header)
         throws eap.fits.FitsCardException
Create a data object with the correct size for the given header. Note that this just creates a generic data object. Use createFrom(FitsHeader) if you want to create a data object of the appropriate type

Parameters:
header - - the header to use to derive the size of the data.
Throws:
FitsCardException - if the header is not properly formed.
See Also:
createFrom(FitsHeader)
Method Detail

blockCount

public int blockCount()
returns the number of blocks (including partial blocks) in the data


data

protected byte[] data()
returns the raw data array


setValidBytes

public void setValidBytes(int valid_bytes)
                   throws FitsException
update the number of bytes which have been set in the data array. This method is used by the subclasses of FitsFile to indicate the fraction of the raw data array which has been read from a data source. This method should not be called by the general user.

Parameters:
valid_bytes - the new number of valid bytes in the raw data array
Throws:
FitsException - never, however subclasses may do so.
See Also:
FitsFile.getHDU(int, int)

incrementValidBytes

public void incrementValidBytes(int new_bytes)
                         throws FitsException
adjust the number of valid bytes by a given increment.

Parameters:
new_bytes - the change in the number of valid bytes
Throws:
FitsException - never, however subclasses may do so.
See Also:
setValidBytes(int)

isComplete

public boolean isComplete()
returns true if the data array has been completely read. This will only return false if FitsFile.getHDU(int, int) was called with the FitsFile.NEED_DATA_LATER hint.


createFrom

public static FitsData createFrom(FitsHeader header)
                           throws FitsException
This is a factory method to produce a FitsData object of the appropriate type corresponding to a given header

Parameters:
header - the header specifying the size and type of the data
Returns:
a new FitsData structure of the proper type. Usually this will be a subclass of FitsData.
Throws:
FitsException - if the header was malformed.

goToByte

public void goToByte(long new_position)
reposition the data reader and writer streams to a given offset in the raw data array.


available

protected int available()
returns the number of bytes remaining in the raw data array between the current position and the end of the array.