public class FitsArrayBuilder extends Object implements ArrayBuilder
URLs are given in the format
fits-url.fitor
fits-url.fitwhere the[
hdu-num]
[]
represent literal square brackets
or
fits-url.fit#
hdu-num
where the #
represents a literal hash sign.
The fits-url.fit represents the full absolute or relative URL
of a FITS file, and the hdu-num, if present, is the index
of the HDU within it. If no HDU is given, the first HDU
(hdu-num=0) is understood.
When writing a new NDArray, if hdu-num==0 then any existing FITS file of the same name will be erased. It is possible to write to HDUs after the first one by specifying the appropriate hdu-num, but only if this refers to the first non-existent HDU in an existing FITS file.
This is a singleton class; use getInstance()
to get an instance.
Modifier and Type | Method and Description |
---|---|
static FitsArrayBuilder |
getInstance()
Returns a FitsArrayBuilder.
|
NDArray |
makeNDArray(ArrayDataInput stream,
AccessMode mode)
Makes a readable NDArray from a data input stream.
|
NDArray |
makeNDArray(URL url,
AccessMode mode)
Constructs an NDArray based on the existing resource at a given URL.
|
NDArray |
makeNewNDArray(OutputStream stream,
NDShape shape,
Type type,
BadHandler bh,
boolean primary,
HeaderCard[] cards)
Makes a new HDU written into a given stream containing an NDArray
with the type and shape as specified.
|
NDArray |
makeNewNDArray(URL url,
NDShape shape,
Type type,
BadHandler bh)
Makes a new HDU at a given URL containing an NDArray with the
shape and type as specified.
|
public static FitsArrayBuilder getInstance()
public NDArray makeNDArray(URL url, AccessMode mode) throws IOException
ArrayBuilder
null
should be returned.
If the resource exists but some error occurs in processing it,
or if this factory knows that it understands the URL but is
unable to locate such a resource then an IOException should be
thrown; however, if it is possible that a different factory could
correctly construct an NDArray from this URL then a null return
is preferred.
If the resource storing the NDArray is incapable of storing bad values,
an NDArray using the
default bad value handling policy
should be returned.
makeNDArray
in interface ArrayBuilder
url
- the URL of the resource from which an NDArray is to
be constructedmode
- the read/update/write mode with which to create the arrayurl
, or null
if this
handler does not recognise the URLIOException
- if the URL is understood but an NDArray cannot
be madepublic NDArray makeNDArray(ArrayDataInput stream, AccessMode mode) throws IOException
stream
implements ArrayDataOutput
.stream
- the input stream supplying the HDU at which the
FITS array data can be foundmode
- read/write/update access modestream
IOException
- if some I/O error occurs or the stream does
not contain FITS array datapublic NDArray makeNewNDArray(URL url, NDShape shape, Type type, BadHandler bh) throws IOException
file:
protocol, and if it is equal to
the number of HDUs currently in the FITS file.makeNewNDArray
in interface ArrayBuilder
url
- the URL at which the resource backing the NDArray is
to be writtenshape
- the shape of the new NDArray to constructtype
- the primitive data type of the new NDArray to constructbh
- requested bad value handling policynull
if the URL doesn't look
like a FITS fileIOException
- if the URL is a FITS URL but the requested
NDArray cannot be constructed for some reasonpublic NDArray makeNewNDArray(OutputStream stream, NDShape shape, Type type, BadHandler bh, boolean primary, HeaderCard[] cards) throws IOException
stream
- the stream down which the NDArray is to be writtenshape
- the shape of the new NDArray to constructtype
- the primitive data type of the new NDArray to constructbh
- requested bad value handling policyprimary
- whether this is the primary HDU (first in file)cards
- array of additional FITS header cards to add - may be nullIOException
- if there is some I/O errorCopyright © 2025 Central Laboratory of the Research Councils. All Rights Reserved.