public class Fits extends Object implements Closeable
This FITS package attempts to make using FITS files easy, but does not do exhaustive error checking. Users should not assume that just because a FITS file can be read and written that it is necessarily legal FITS. These classes try to make it easy to transform between arrays of Java primitives and their FITS encodings.
Note that this association is limited, it only specifies where the various read methods should read data from. It does not automatically read the data content and store the results. To ensure that the external content has been read and parsed the user may wish to invoke the read() method after creating the Fits object associated with external data. E.g.,
File fl = ... ; Fits f = new Fits(fl); // Or we could have used one of the other constructors. // At this point the Fits object is empty. f.read(); // Read the external data into the Fits object // At this point the Fits object should have one or more HDUs depending // upon the external content.Users can choose to read only some of the HDUs in a given input, and may add HDU's that were either read from other files or generated by the program. See the various read and addHDU methods.
Constructor and Description |
---|
Fits()
Create an empty Fits object which is not associated with an input stream.
|
Fits(File myFile)
Associate FITS object with a File.
|
Fits(File myFile,
boolean compressed)
Associate the Fits object with a File
|
Fits(InputStream str)
Create a Fits object associated with the given data stream.
|
Fits(InputStream str,
boolean compressed)
Deprecated.
use
Fits(InputStream) compression is auto detected. |
Fits(String filename)
Associate the FITS object with a file or URL.
|
Fits(String filename,
boolean compressed)
Associate the FITS object with a file or URL.
|
Fits(URL myURL)
Associate the FITS object with a given URL
|
Fits(URL myURL,
boolean compressed)
Deprecated.
use
Fits(InputStream) compression is auto detected. |
Modifier and Type | Method and Description |
---|---|
void |
addHDU(BasicHDU<?> myHDU)
Add an HDU to the Fits object.
|
static long |
checksum(byte[] data)
Deprecated.
|
void |
close() |
int |
currentSize()
Deprecated.
use
getNumberOfHDUs() instead |
void |
deleteHDU(int n)
Delete an HDU from the HDU list.
|
protected void |
fileInit(File myFile,
boolean compressed)
Get a stream from the file and then use the stream initialization.
|
BasicHDU<?> |
getHDU(int n) |
int |
getNumberOfHDUs()
Get the current number of HDUs in the Fits object.
|
ArrayDataInput |
getStream()
Get the data stream used for the Fits Data.
|
void |
insertHDU(BasicHDU<?> myHDU,
int position)
Insert a FITS object into the list of HDUs.
|
static <DataClass extends Data> |
makeHDU(DataClass data) |
static BasicHDU<?> |
makeHDU(Header h) |
static BasicHDU<?> |
makeHDU(Object o) |
protected void |
randomInit(File file)
Initialize using buffered random access.
|
BasicHDU<?>[] |
read()
Return all HDUs for the Fits object.
|
void |
read(InputStream is)
Read a FITS file from an InputStream object.
|
BasicHDU<?> |
readHDU()
Read the next HDU on the default input stream.
|
static void |
saveClose(InputStream in)
close the input stream, and ignore eventual errors.
|
void |
setChecksum()
Add or Modify the CHECKSUM keyword in all headers.
|
static void |
setChecksum(BasicHDU<?> hdu)
Deprecated.
|
void |
setStream(ArrayDataInput stream)
Set the data stream to be used for future input.
|
int |
size()
Deprecated.
The meaning of size of ambiguous. Use
getNumberOfHDUs() instead. Note size() will read the
input file/stream to the EOF before returning the number of
HDUs which getNumberOfHDUs() does not. If you wish
to duplicate this behavior and ensure that the input has been
exhausted before getting the number of HDUs then use the
sequence:
read();
getNumberofHDUs();
|
void |
skipHDU()
Skip the next HDU on the default input stream.
|
void |
skipHDU(int n)
Skip HDUs on the associate input stream.
|
protected void |
streamInit(InputStream inputStream)
Initialize the input stream.
|
static String |
version() |
void |
write(DataOutput os)
Write a Fits Object to an external Stream.
|
void |
write(File file)
Write the FITS to the specified file.
|
public Fits()
public Fits(File myFile) throws FitsException
myFile
- The File object. The content of this file will not be read
into the Fits object until the user makes some explicit
request. * @throws FitsException if the operation failedFitsException
- if the operation failedpublic Fits(File myFile, boolean compressed) throws FitsException
myFile
- The File object. The content of this file will not be read
into the Fits object until the user makes some explicit
request.compressed
- Is the data compressed?FitsException
- if the operation failedpublic Fits(InputStream str) throws FitsException
str
- The data stream. The content of this stream will not be read
into the Fits object until the user makes some explicit
request.FitsException
- if the operation failed@Deprecated public Fits(InputStream str, boolean compressed) throws FitsException
Fits(InputStream)
compression is auto detected.str
- The data stream. The content of this stream will not be read
into the Fits object until the user makes some explicit
request.compressed
- Is the stream compressed? This is currently ignored.
Compression is determined from the first two bytes in the
stream.FitsException
- if the operation failedpublic Fits(String filename) throws FitsException
filename
- The name of the file or URL to be processed. The content of
this file will not be read into the Fits object until the user
makes some explicit request.FitsException
- Thrown if unable to find or open a file or URL from the
string given.public Fits(String filename, boolean compressed) throws FitsException
filename
- The name of the file or URL to be processed. The content of
this file will not be read into the Fits object until the user
makes some explicit request.compressed
- is the file compressed?FitsException
- Thrown if unable to find or open a file or URL from the
string given.public Fits(URL myURL) throws FitsException
myURL
- The URL to be read. The content of this URL will not be read
into the Fits object until the user makes some explicit
request.FitsException
- Thrown if unable to find or open a file or URL from the
string given.@Deprecated public Fits(URL myURL, boolean compressed) throws FitsException
Fits(InputStream)
compression is auto detected.myURL
- The URL to be associated with the FITS file. The content of
this URL will not be read into the Fits object until the user
makes some explicit request.compressed
- Compression flag, ignored.FitsException
- Thrown if unable to use the specified URL.public static <DataClass extends Data> BasicHDU<DataClass> makeHDU(DataClass data) throws FitsException
DataClass
- the class of the HDUdata
- The data to be described in this HDU.FitsException
- if the operation failedpublic static BasicHDU<?> makeHDU(Header h) throws FitsException
h
- The header which describes the FITS extensionFitsException
- if the header could not be converted to a HDU.public static BasicHDU<?> makeHDU(Object o) throws FitsException
o
- The data to be described in this HDU.FitsException
- if the parameter could not be converted to a HDU.public static String version()
public static void saveClose(InputStream in)
in
- the input stream to close.public void addHDU(BasicHDU<?> myHDU) throws FitsException
myHDU
- The HDU to be added to the end of the FITS object.FitsException
- if the HDU could not be inserted.@Deprecated public int currentSize()
getNumberOfHDUs()
insteadpublic void deleteHDU(int n) throws FitsException
n
- The index of the HDU to be deleted. If n is 0 and there is
more than one HDU present, then the next HDU will be converted
from an image to primary HDU if possible. If not a dummy
header HDU will then be inserted.FitsException
- if the HDU could not be deleted.protected void fileInit(File myFile, boolean compressed) throws FitsException
myFile
- The File to be associated.compressed
- Is the data compressed?FitsException
- if the opening of the file failed.public BasicHDU<?> getHDU(int n) throws FitsException, IOException
n
- The index of the HDU to be read. The primary HDU is index 0.FitsException
- if the header could not be readIOException
- if the underlying buffer threw an errorpublic int getNumberOfHDUs()
public ArrayDataInput getStream()
public void insertHDU(BasicHDU<?> myHDU, int position) throws FitsException
myHDU
- The HDU to be inserted into the list of HDUs.position
- The location at which the HDU is to be inserted.FitsException
- if the HDU could not be inserted.protected void randomInit(File file) throws FitsException
file
- the file to openFitsException
- if the file could not be readpublic BasicHDU<?>[] read() throws FitsException
FitsException
- if the reading failed.public void read(InputStream is) throws FitsException
is
- The InputStream stream whence the FITS information is found.FitsException
- if the data read could not be interpretedpublic BasicHDU<?> readHDU() throws FitsException, IOException
FitsException
- if the header could not be readIOException
- if the underlying buffer threw an errorpublic void setChecksum() throws FitsException, IOException
FitsException
- if the operation failedIOException
- if the underlying stream failedpublic void setStream(ArrayDataInput stream)
stream
- The data stream to be used.@Deprecated public int size() throws FitsException
getNumberOfHDUs()
instead. Note size() will read the
input file/stream to the EOF before returning the number of
HDUs which getNumberOfHDUs()
does not. If you wish
to duplicate this behavior and ensure that the input has been
exhausted before getting the number of HDUs then use the
sequence:
read();
getNumberofHDUs();
FitsException
- if the file could not be read.public void skipHDU() throws FitsException, IOException
FitsException
- if the HDU could not be skippedIOException
- if the underlying stream failedpublic void skipHDU(int n) throws FitsException, IOException
n
- The number of HDUs to be skipped.FitsException
- if the HDU could not be skippedIOException
- if the underlying stream failedprotected void streamInit(InputStream inputStream) throws FitsException
inputStream
- stream to initializeFitsException
- if the initialization failedpublic void write(DataOutput os) throws FitsException
os
- A DataOutput stream.FitsException
- if the operation failedpublic void write(File file) throws IOException, FitsException
write(DataOutput)
method. It
creates a suitable BufferedFile
, to which the FITS
is then written. Upon completion the underlying stream is closed.file
- a file to which the FITS is to be written.FitsException
- if write(DataOutput)
failedIOException
- if the underlying output stream could not be created or
closed.public void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
IOException
@Deprecated public static void setChecksum(BasicHDU<?> hdu) throws FitsException
FitsCheckSum.setChecksum(BasicHDU)
hdu
- the HDU to add a checksumFitsException
- the checksum could not be added to the header@Deprecated public static long checksum(byte[] data)
FitsCheckSum.checksum(byte[])
data
- the data to create the checksum forCopyright © 1996–2016 nom-tam-fits. All rights reserved.