Package nom.tam.fits
Class Data
java.lang.Object
nom.tam.fits.Data
- All Implemented Interfaces:
FitsElement
- Direct Known Subclasses:
AbstractTableData
,ImageData
,RandomGroupsData
,UndefinedData
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
-
Method Summary
Modifier and TypeMethodDescriptionlong
Computes and returns the FITS checksum for this data, for example to compare against the storedDATASUM
in the FITS header (e.g. viaBasicHDU.getStoredDatasum()
).void
detach()
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.getData()
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 asgetData()
.long
getSize()
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
isEmpty()
Checks if the data content is currently empty, i.e. no actual data is currently stored in memory.void
read
(ArrayDataInput in) 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()
Reset the input stream to point to the beginning of this elementvoid
rewrite()
Rewrite the contents of the element in place.boolean
Checks if we can write this element back to its source.abstract BasicHDU<?>
toHDU()
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.
-
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 elsefalse
if this data is currently loaded into RAM. #seedetach()
- 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, otherwisefalse
- Since:
- 1.18
- See Also:
-
isDeferred()
getCurrentData()
-
calcChecksum
Computes and returns the FITS checksum for this data, for example to compare against the storedDATASUM
in the FITS header (e.g. viaBasicHDU.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 fileBasicHDU.verifyDataIntegrity()
orBasicHDU.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
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:
-
isDeferred()
ensureData()
-
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 interfaceFitsElement
- 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
Same asgetData()
.- 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 interfaceFitsElement
- Returns:
- The size of this element in bytes, or 0 if the element is empty or invalid.
-
read
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 aFitsFile
, 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 interfaceFitsElement
- 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:
-
getData()
ensureData()
-
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 interfaceFitsElement
- Returns:
- True if the reset succeeded.
-
rewrite
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 interfaceFitsElement
- 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 interfaceFitsElement
- Returns:
true
if this element can be rewritten?
-
detach
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
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 interfaceFitsElement
- Parameters:
o
- The data sink.- Throws:
FitsException
- if the write was unsuccessful.
-
toHDU
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.
-