# Class FitsTableWriter

java.lang.Object
uk.ac.starlink.table.StreamStarTableWriter
uk.ac.starlink.fits.AbstractFitsTableWriter
uk.ac.starlink.fits.FitsTableWriter

All Implemented Interfaces:
  `uk.ac.starlink.table.MultiStarTableWriter, uk.ac.starlink.table.StarTableWriter`

public class FitsTableWriter extends AbstractFitsTableWriter
Handles writing of a StarTable in FITS binary format. Not all columns can be written to a FITS table, only those ones whose `contentClass` is in the following list:

- Boolean
- Character
- Byte
- Short
- Integer
- Long
- Float
- Double
- Character
- String
- boolean[]
- char[]
- byte[]
- short[]
- int[]
- long[]
- float[]
- double[]
- String[]

In all other cases a warning message will be logged and the column will be ignored for writing purposes.

Output is currently to fixed-width columns only. For StarTable columns of variable size, a first pass is made through the table data to determine the largest size they assume, and the size in the output table is set to the largest of these. Excess space is padded with some sort of blank value (NaN for floating point values, spaces for strings, zero-like values otherwise).

Author:
  Mark Taylor (Starlink)

## Nested Class Summary

Nested Classes
Modifier and Type
Class
Description
`static class`
`FitsTableWriter.PrimaryType`
Characterises the type of Primary HDU that will precede table extensions written by this writer.
`static enum`
`FitsTableWriter.VarArrayMode`
Enumeration for variable-length array value storage options.

## Constructor Summary

Constructors
Constructor
Description
`FitsTableWriter()`
Default constructor.
`FitsTableWriter(String name, boolean allowSignedByte, WideFits wide)`
Deprecated.
allows some configuration options but not others; use no-arg constructor and configuration methods instead

## Method Summary

Modifier and Type
Method
Description
`FitsTableSerializer`
`createSerializer(uk.ac.starlink.table.StarTable table)`
Provides a suitable serializer for a given table.
`boolean`
`getAllowSignedByte()`
Returns a flag indicating how Byte-valued columns are written.
`FitsTableWriter.PrimaryType`
`getPrimaryType()`
Returns the type of Primary HDU that will precede the extension HDU(s) corresponding to the table(s) being written.
`uk.ac.starlink.table.StoragePolicy`
`getStoragePolicy()`
Returns the storage policy that will be used if required.
`FitsTableWriter.VarArrayMode`
`getVarArray()`
Indicates how variable-length array valued columns will be stored.
`boolean`
`isColfits()`
Returns whether table data will be written in column-oriented form.
`boolean`
`looksLikeFile(String location)`
Returns true if `location` ends with something like ".fit" or ".fits" or ".fts".
`void`
`setColfits(boolean colfits)`
Sets whether table data should be written in column-oriented form.
`void`
`setPrimaryType(FitsTableWriter.PrimaryType primaryType)`
Sets the type of Primary HDU that will precede the extension HDU(s) corresponding to the table(s) being written.
`void`
`setStoragePolicy(uk.ac.starlink.table.StoragePolicy storage)`
Sets the storage policy to use where required.
`void`
`setVarArray(FitsTableWriter.VarArrayMode varArray)`
Configures how variable-length array values will be stored.
`void`
`writeStarTables(uk.ac.starlink.table.TableSequence tableSeq, OutputStream out)`
Writes tables.

### Methods inherited from class AbstractFitsTableWriter

`getAllowZeroLengthString, getConfig, getCurrentDate, getFormatName, getMetadataCards, getMimeType, getPadCharacter, getWide, getWriteDate, setAllowSignedByte, setAllowZeroLengthString, setFormatName, setPadCharacter, setWide, setWriteDate, writePrimaryHDU, writeStarTable, writeStarTables, writeTableHDU`

### Methods inherited from class uk.ac.starlink.table.StreamStarTableWriter

`writeStarTable, writeStarTable`

### Methods inherited from class Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Methods inherited from interface uk.ac.starlink.table.StarTableWriter

`writeStarTable`

## Constructor Details

### FitsTableWriter

public FitsTableWriter()
Default constructor.

### FitsTableWriter

@Deprecated public FitsTableWriter(String name, boolean allowSignedByte, WideFits wide)
Deprecated.
allows some configuration options but not others; use no-arg constructor and configuration methods instead
Deprecated custom constructor.

## Method Details

### looksLikeFile

public boolean looksLikeFile(String location)
Returns true if `location` ends with something like ".fit" or ".fits" or ".fts".

Parameters:
  `location` - filename
Returns:
  true if it sounds like a fits file

### setPrimaryType

public void setPrimaryType(FitsTableWriter.PrimaryType primaryType)
Sets the type of Primary HDU that will precede the extension HDU(s) corresponding to the table(s) being written.

Parameters:
  `primaryType` - type of primary HDU

### getPrimaryType

public FitsTableWriter.PrimaryType getPrimaryType()
Returns the type of Primary HDU that will precede the extension HDU(s) corresponding to the table(s) being written.

Returns:
  type of primary HDU

### setColfits

public void setColfits(boolean colfits)
Sets whether table data should be written in column-oriented form. If true, the output will be a single-row table of array-valued columns, in which each cell is an array with `nrow` elements.

Parameters:
  `colfits` - true for column-oriented, false for row-oriented

### isColfits

public boolean isColfits()
Returns whether table data will be written in column-oriented form.

Returns:
  true for column-oriented, false for row-oriented

### setVarArray

public void setVarArray(FitsTableWriter.VarArrayMode varArray)
Configures how variable-length array values will be stored.

Parameters:
  `varArray` - variable-length array storage mode

### getVarArray

public FitsTableWriter.VarArrayMode getVarArray()
Indicates how variable-length array valued columns will be stored.

Returns:
  variable-length array storage mode

### setStoragePolicy

public void setStoragePolicy(uk.ac.starlink.table.StoragePolicy storage)
Sets the storage policy to use where required. This is only relevant for column-oriented output, for which data has to be cached before rewriting it.

Parameters:
  `storage` - storage policy to use when writing colfits

### getStoragePolicy

public uk.ac.starlink.table.StoragePolicy getStoragePolicy()
Returns the storage policy that will be used if required.

Returns:
  storage policy used when writing colfits

### getAllowSignedByte

public boolean getAllowSignedByte()
Description copied from class: `AbstractFitsTableWriter`
Returns a flag indicating how Byte-valued columns are written.

Overrides:
  `getAllowSignedByte` in class `AbstractFitsTableWriter`
Returns:
  true to write offset bytes, false to write shorts

### createSerializer

public FitsTableSerializer createSerializer(uk.ac.starlink.table.StarTable table) throws IOException
Description copied from class: `AbstractFitsTableWriter`
Provides a suitable serializer for a given table. Note this should throw an IOException if it can be determined that the submitted table cannot be written by this writer, for instance if it has too many columns.

Specified by:
  `createSerializer` in class `AbstractFitsTableWriter`
Parameters:
  `table` - table to serialize
Returns:
  FITS serializer
Throws:
  `IOException` - if the table can't be written

### writeStarTables

public void writeStarTables(uk.ac.starlink.table.TableSequence tableSeq, OutputStream out) throws IOException
Description copied from class: `AbstractFitsTableWriter`
Writes tables. Calls `AbstractFitsTableWriter.writePrimaryHDU(java.io.OutputStream)` to write the primary HDU. Subclasses which want to put something related to the input tables into the primary HDU will need to override this method (writeStarTables).

Specified by:
  `writeStarTables` in interface `uk.ac.starlink.table.MultiStarTableWriter`
Overrides:
  `writeStarTables` in class `AbstractFitsTableWriter`
Throws:
  `IOException`