Package uk.ac.starlink.fits
Class CardFactory
java.lang.Object
uk.ac.starlink.fits.CardFactory
Creates FITS CardImages suitable for writing to a FITS header.
Different factory instances are available with variant options
for header construction.
Attempts to construct illegal FITS headers will generally provoke RuntimeExceptions.
- Since:
- 4 Mar 2022
- Author:
- Mark Taylor
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final CardFactory
Instance with value trimming, bad char replacement, no HIERARCH.static final CardFactory
Default instance (currentlyCLASSIC
).static final CardImage
CardImage for terminating header ("END").static final CardFactory
Instance with value trimming, bad char replacement, and HIERARCH.static final CardFactory
Instance with no value trimming, bad char rejection, no HIERARCH. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncreateCommentCard
(String txt) Constructs a COMMENT card with the given comment.createIntegerCard
(String key, long value, String comment) Constructs a key-value card with integer content.createLiteralCard
(String key, String literal, String comment) Constructs a key-value card with given literal text for the value part.createLogicalCard
(String key, boolean value, String comment) Constructs a key-value card with logical content.createPlainCard
(String txt) Constructs a card containing the given exact text.createRealCard
(String key, double value, String comment) Constructs a key-value card with floating point content.createStringCard
(String key, String value, String comment) Constructs a key-value card with string content.Returns the configuration state of this factory.static String
sanitiseAsError
(String txt) Utility string sanitisation function that throws an IllegalArgumentException if any illegal characters are present.static String
sanitiseByReplacement
(String txt, char replaceChar) Utility string sanitisation function that replaces illegal characters by a given char.
-
Field Details
-
CLASSIC
Instance with value trimming, bad char replacement, no HIERARCH. -
HIERARCH
Instance with value trimming, bad char replacement, and HIERARCH. -
STRICT
Instance with no value trimming, bad char rejection, no HIERARCH. -
DEFAULT
Default instance (currentlyCLASSIC
). -
END_CARD
CardImage for terminating header ("END").
-
-
Constructor Details
-
CardFactory
Constructor.- Parameters:
config
- factory configuration
-
-
Method Details
-
getConfig
Returns the configuration state of this factory.- Returns:
- config object
-
createPlainCard
Constructs a card containing the given exact text. It is padded with spaces if necessary. No sanitisation or trimming is performed.- Parameters:
txt
- literal card content, <=80 characters- Returns:
- new card
-
createCommentCard
Constructs a COMMENT card with the given comment. The text may be sanitised and trimmed if too long according to policy.- Parameters:
txt
- comment text- Returns:
- new card
-
createStringCard
Constructs a key-value card with string content. The value and comment may be sanitised and trimmed if too long according to policy.- Parameters:
key
- header keywordvalue
- header valuecomment
- comment text, or null- Returns:
- new card
-
createIntegerCard
Constructs a key-value card with integer content. The comment may be sanitised and trimmed if too long according to policy.- Parameters:
key
- header keywordvalue
- header valuecomment
- comment text, or null- Returns:
- new card
-
createRealCard
Constructs a key-value card with floating point content. The comment may be sanitised and trimmed if too long according to policy.- Parameters:
key
- header keywordvalue
- header valuecomment
- comment text, or null- Returns:
- new card
-
createLogicalCard
Constructs a key-value card with logical content. The comment may be sanitised and trimmed if too long according to policy.- Parameters:
key
- header keywordvalue
- header valuecomment
- comment text, or null- Returns:
- new card
-
createLiteralCard
Constructs a key-value card with given literal text for the value part. No additional quoting or escaping is performed on the provided string, but both string and comment may be trimmed in a string-sensitive way according to policy.The key must contain only legal key characters, and the literal and comment must contain only legal header characters.
- Parameters:
key
- header keywordliteral
- formatted value textcomment
- comment text, or null- Returns:
- new card
- Throws:
IllegalArgumentException
- if inputs are not suitable for FITS
-
sanitiseByReplacement
Utility string sanitisation function that replaces illegal characters by a given char.- Parameters:
txt
- input textreplaceChar
- character to replace non-FITS characters- Returns:
- same as
txt
, but with non-FITS characters replaced byreplaceChar
-
sanitiseAsError
Utility string sanitisation function that throws an IllegalArgumentException if any illegal characters are present.- Parameters:
txt
- input text- Returns:
- input text
- Throws:
IllegalArgumentException
- if non-FITS characters are present
-