public class FitsTableBuilder extends DocumentedTableBuilder implements MultiTableBuilder
TableBuilder
interface which
gets StarTable
s from FITS files.
The table implementation used by uncompressed binary FITS tables
stored on disk maps the file into memory
(MappedByteBuffer
) rather than reading the stream as such;
this makes table construction very fast and cheap on memory, regardless of
storage policy. This behaviour can be inhibited by referring to the
file location as a URL (e.g. "file:spec23.fits" rather than "spec23.fits"),
which fools the handler into thinking that it can't be mapped.
Limited support is provided for the
HEALPix-FITS convention;
the relevant HealpixTableInfo
table parameters
are added, but any BAD_DATA keyword value is ignored,
and the 1024-element array-valued column variant of the format is not
understood.
Constructor and Description |
---|
FitsTableBuilder()
Default constructor.
|
FitsTableBuilder(WideFits wide)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
static StarTable |
attemptReadTable(InputStream in,
boolean wantRandom,
DataSource datsrc,
WideFits wide,
long[] pos,
StoragePolicy policy)
Reads the next header, and returns a StarTable based on it if it
represents a table.
|
boolean |
canImport(DataFlavor flavor)
Returns
true for a flavor with the MIME type
"application/fits". |
boolean |
canStream()
Indicates whether this handler can read tables from a stream.
|
boolean |
docIncludesExample()
Indicates whether the serialization of some (short) example table
should be added to the user documentation for this handler.
|
static StarTable |
findNamedTable(InputStream in,
DataSource datsrc,
String name,
WideFits wide,
long[] pos,
StoragePolicy policy)
Looks through the HDUs in a given FITS stream and if it finds
one which has a given name, attempts to make a table out of it.
|
String |
getFormatName()
Returns "FITS".
|
String |
getXmlDescription()
Returns user-directed documentation in XML format.
|
StarTable |
makeStarTable(DataSource datsrc,
boolean wantRandom,
StoragePolicy policy)
Creates a StarTable from a DataSource which refers to a FITS
file or stream.
|
TableSequence |
makeStarTables(DataSource datsrc,
StoragePolicy policy)
Constructs a sequence of StarTables based on a given DataSource.
|
void |
streamStarTable(InputStream in,
TableSink sink,
String extnum)
Reads a FITS table from an input stream and writes it to a sink.
|
getExtensions, looksLikeFile
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
looksLikeFile
matchesExtension, readText, toLink
public FitsTableBuilder()
public FitsTableBuilder(WideFits wide)
wide
- convention for representing extended columns;
use null to avoid use of extended columnspublic String getFormatName()
getFormatName
in interface TableBuilder
public StarTable makeStarTable(DataSource datsrc, boolean wantRandom, StoragePolicy policy) throws IOException
If the EXTNAME happens to be in the form of a positive integer, this means you can't refer to the extension by name. Too bad.
If there is no position attribute, the first HDU which does hold a table is used.
makeStarTable
in interface TableBuilder
datsrc
- the source of the FITS table datawantRandom
- whether a random-access table is preferredpolicy
- a StoragePolicy object which may be used to
supply scratch storage if the builder needs itdatsrc
,
or null
if it doesn't look like a FITS tableTableFormatException
- if the table is not of a kind that
can be handled by this handlerIOException
- if an unexpected I/O error occurs during processingpublic TableSequence makeStarTables(DataSource datsrc, StoragePolicy policy) throws IOException
MultiTableBuilder
TableFormatException
should be thrown. If this builder thinks it should be able to
handle the source but an error occurs during processing, an
IOException
can be thrown.
If the position
of the data source is not null,
then this method should return a sequence containing a single table,
the one which would be returned by the makeStarTable
method with that position.
makeStarTables
in interface MultiTableBuilder
datsrc
- the DataSource containing the table resourcepolicy
- a StoragePolicy object which may be used to
supply scratch storage if the builder needs itdatsrc
TableFormatException
- if the table is not of a kind that
can be handled by this handlerIOException
- if an unexpected I/O error occurs during processingpublic boolean canImport(DataFlavor flavor)
true
for a flavor with the MIME type
"application/fits".canImport
in interface TableBuilder
flavor
- the DataFlavor whose suitability as stream input
is to be assessedtrue
iff this builder reckons it stands a good
chance of turning a stream of type flavor
into a
StarTable
public void streamStarTable(InputStream in, TableSink sink, String extnum) throws IOException
streamStarTable
in interface TableBuilder
in
- input stream containing the FITS datasink
- destination for table dataextnum
- may contain a string representation of the HDU
number in which the required table is found (otherwise the
first table HDU will be used)TableFormatException
- if the table can't be streamed or
the data is malformedIOException
- if some other error occurspublic boolean canStream()
DocumentedTableBuilder
canStream
in class DocumentedTableBuilder
public boolean docIncludesExample()
DocumentedIOHandler
Documented.getXmlDescription()
method already includes some example output, should return false.docIncludesExample
in interface DocumentedIOHandler
public String getXmlDescription()
Documented
The output should be a sequence of one or more <P> elements, using XHTML-like XML. Since rendering may be done in a number of contexts however, use of the full range of XHTML elements is discouraged. Where possible, the content should stick to simple markup such as the elements P, A, UL, OL, LI, DL, DT, DD EM, STRONG, I, B, CODE, TT, PRE.
getXmlDescription
in interface Documented
public static StarTable findNamedTable(InputStream in, DataSource datsrc, String name, WideFits wide, long[] pos, StoragePolicy policy) throws IOException
name
is checked against the EXTNAME
header value (if present), and if that fails, against EXTNAME-EXTVER
(if EXTVER is present too). Matching is case-insensitive.in
- stream to read from, positioned at the start of an HDU
(before the header)datsrc
- a DataSource which can supply the data
in strm
name
- target extension name or name-versionwide
- convention for representing extended columns;
use null to avoid use of extended columnspos
- a 1-element array holding the position
in datsrc
at which strm
is positioned -
it's an array so it can be updated by this routine (sorry)policy
- storage policy, or null for default (normally not used)IOException
public static StarTable attemptReadTable(InputStream in, boolean wantRandom, DataSource datsrc, WideFits wide, long[] pos, StoragePolicy policy) throws IOException
null
is
returned and the stream is advanced to the end of that HDU;
in this case the stream may continue to be used (e.g. for
further calls to this method).
On exit, the first element of the pos
array
contains the position after the current HDU.
in
- stream to read from, positioned at the start of an HDU
(before the header)wantRandom
- whether a random-access table is preferreddatsrc
- a DataSource which can supply the data
in strm
wide
- convention for representing extended columns;
use null to avoid use of extended columnspos
- a 1-element array holding the position
in datsrc
at which strm
is positioned -
it's an array so it can be updated by this routine (sorry)policy
- storage policy, or null for default (normally not used)strm
or nullIOException
Copyright © 2024 Central Laboratory of the Research Councils. All Rights Reserved.