Package nom.tam.util
Class FitsEncoder
java.lang.Object
nom.tam.util.OutputEncoder
nom.tam.util.FitsEncoder
- Direct Known Subclasses:
BufferEncoder
Encodes select Java arrays into FITS binary format (primarily for internal use)
- Since:
- 1.16
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class nom.tam.util.OutputEncoder
OutputEncoder.OutputBuffer
-
Field Summary
Fields inherited from class nom.tam.util.OutputEncoder
out
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
Instantiates a new encoder from Java arrays to FITS binary output.Instantiates a new FITS binary data encoder for converting Java arrays into FITS data representations -
Method Summary
Modifier and TypeMethodDescriptionstatic byte
Returns the FITS byte value representing a logical value.static long
Returns the size of this object as the number of bytes in a FITS binary representation.protected void
Puts a Java array into the conversion buffer, but with no guarantee of flushing the conversion buffer to the underlying output.protected void
write
(boolean[] b, int start, int length) SeeArrayDataOutput.write(boolean[], int, int)
for the general contract of this method.protected void
write
(char[] c, int start, int length) SeeArrayDataOutput.write(char[], int, int)
for the general contract of this method.protected void
write
(double[] d, int start, int length) SeeArrayDataOutput.write(double[], int, int)
for a contract of this method.protected void
write
(float[] f, int start, int length) SeeArrayDataOutput.write(float[], int, int)
for a contract of this method.protected void
write
(int[] i, int start, int length) SeeArrayDataOutput.write(int[], int, int)
for a contract of this method.protected void
write
(long[] l, int start, int length) SeeArrayDataOutput.write(long[], int, int)
for a contract of this method.protected void
write
(short[] s, int start, int length) SeeArrayDataOutput.write(short[], int, int)
for a contract of this method.protected void
SeeArrayDataOutput.write(Boolean[], int, int)
for the general contract of this method.protected void
SeeArrayDataOutput.write(String[], int, int)
for a contract of this method.void
writeArray
(Object o) Writes the contents of a Java array to the output translating the data to the required binary representation.protected void
Deprecated.(for internal use) Low-level reading/writing should be handled internally as arrays by this library only.protected void
writeByte
(int b) Deprecated.(for internal use) Low-level reading/writing should be handled internally as arrays by this library only.protected void
writeBytes
(String s) Writes a Java string as a sequence of ASCII bytes to the output.protected void
writeChar
(int c) Deprecated.(for internal use) Low-level reading/writing should be handled internally as arrays by this library only.protected void
writeChars
(String s) In FITS characters are usually represented as 1-byte ASCII, not as the 2-byte Java types.protected void
writeDouble
(double d) Deprecated.(for internal use) Low-level reading/writing should be handled internally as arrays by this library only.protected void
writeFloat
(float f) Deprecated.(for internal use) Low-level reading/writing should be handled internally by this library only.protected void
writeInt
(int i) Deprecated.(for internal use) Low-level reading/writing should be handled internally as arrays by this library only.protected void
writeLong
(long l) Deprecated.(for internal use) Low-level reading/writing should be handled internally as arrays by this library only.protected void
writeShort
(int s) Deprecated.(for internal use) Low-level reading/writing should be handled internally as arrays by this library only.Methods inherited from class nom.tam.util.OutputEncoder
flush, getCount, getOutputBuffer, setOutput, write, write
-
Constructor Details
-
FitsEncoder
protected FitsEncoder()Instantiates a new encoder from Java arrays to FITS binary output. To be used by subclass constructors only. -
FitsEncoder
Instantiates a new FITS binary data encoder for converting Java arrays into FITS data representations- Parameters:
o
- the FITS output.
-
-
Method Details
-
byteForBoolean
Returns the FITS byte value representing a logical value. This call supportsnull
values, which are allowed by the FITS standard. FITS defines 'T' as true, 'F' as false, and 0 as null. Prior versions of this library have used the value 1 for true, and 0 for false. Therefore, this implementation will recognise both 'T' and 1 astrue
, but 0 will map tonull
and everything else will returnfalse
.- Parameters:
b
- A java boolean value ornull
- Returns:
- the FITS byte representation of a boolean value.
-
writeBoolean
Deprecated.(for internal use) Low-level reading/writing should be handled internally as arrays by this library only.- Parameters:
b
- a boolean value ornull
.- Throws:
IOException
- if there was an IO error writing to the output.
-
writeChar
Deprecated.(for internal use) Low-level reading/writing should be handled internally as arrays by this library only.- Parameters:
c
- An ASCII character.- Throws:
IOException
- if there was an IO error writing to the output.
-
write
SeeArrayDataOutput.write(boolean[], int, int)
for the general contract of this method. In FITS,true
values are represented by the ASCII byte for 'T', whereasfalse
is represented by the ASCII byte for 'F'.- Parameters:
b
- array of booleans.start
- the index of the first element in the array to writelength
- number of array elements to write- Throws:
IOException
- if there was an IO error writing to the output
-
write
SeeArrayDataOutput.write(Boolean[], int, int)
for the general contract of this method. In FITS,true
values are represented by the ASCII byte for 'T',false
is represented by the ASCII byte for 'F', whilenull
values are represented by the value 0.- Parameters:
b
- array of booleans.start
- the index of the first element in the array to writelength
- number of array elements to write- Throws:
IOException
- if there was an IO error writing to the output
-
writeByte
Deprecated.(for internal use) Low-level reading/writing should be handled internally as arrays by this library only.- Parameters:
b
- a single byte.- Throws:
IOException
- if there was an IO error writing to the output.
-
writeShort
Deprecated.(for internal use) Low-level reading/writing should be handled internally as arrays by this library only.- Parameters:
s
- a 16-bit integer value.- Throws:
IOException
- if there was an IO error writing to the output.
-
writeInt
Deprecated.(for internal use) Low-level reading/writing should be handled internally as arrays by this library only.- Parameters:
i
- a 32-bit integer value.- Throws:
IOException
- if there was an IO error writing to the output.
-
writeLong
Deprecated.(for internal use) Low-level reading/writing should be handled internally as arrays by this library only.- Parameters:
l
- a 64-bit integer value.- Throws:
IOException
- if there was an IO error writing to the output.
-
writeFloat
Deprecated.(for internal use) Low-level reading/writing should be handled internally by this library only.- Parameters:
f
- a single-precision (32-bit) floating point value.- Throws:
IOException
- if there was an IO error writing to the output.
-
writeDouble
Deprecated.(for internal use) Low-level reading/writing should be handled internally as arrays by this library only.- Parameters:
d
- a double-precision (64-bit) floating point value.- Throws:
IOException
- if there was an IO error writing to the output.
-
writeBytes
Writes a Java string as a sequence of ASCII bytes to the output. FITS does not support unicode characters in its version of strings (character arrays), but instead it is restricted to the ASCII set of 1-byte characters.- Parameters:
s
- the Java string- Throws:
IOException
- if the string could not be fully written to the output- See Also:
-
writeChars
In FITS characters are usually represented as 1-byte ASCII, not as the 2-byte Java types. However, previous implementations if this library have erroneously written 2-byte characters into the FITS. For compatibility both the FITS standard of 1-byte ASCII and the old 2-byte behaviour are supported, and can be selected viaFitsFactory.setUseUnicodeChars(boolean)
.- Parameters:
s
- a string containing ASCII-only characters- Throws:
IOException
- if there was an IO error writing all the characters to the output.- See Also:
-
write
SeeArrayDataOutput.write(char[], int, int)
for the general contract of this method. In FITS characters are usually represented as 1-byte ASCII, not as the 2-byte Java types. However, previous implementations if this library have erroneously written 2-byte characters into the FITS. For compatibility both the FITS standard of 1-byte ASCII and the old 2-byte behaviour are supported, and can be selected viaFitsFactory.setUseUnicodeChars(boolean)
.- Parameters:
c
- array of character (ASCII only is supported).start
- the index of the first element in the array to writelength
- number of array elements to write- Throws:
IOException
- if there was an IO error writing to the output- See Also:
-
write
SeeArrayDataOutput.write(short[], int, int)
for a contract of this method.- Parameters:
s
- array of 16-bit integers.start
- the index of the first element in the array to writelength
- number of array elements to write- Throws:
IOException
- if there was an IO error writing to the output
-
write
SeeArrayDataOutput.write(int[], int, int)
for a contract of this method.- Parameters:
i
- array of 32-bit integers.start
- the index of the first element in the array to writelength
- number of array elements to write- Throws:
IOException
- if there was an IO error writing to the output
-
write
SeeArrayDataOutput.write(long[], int, int)
for a contract of this method.- Parameters:
l
- array of 64-bit integers.start
- the index of the first element in the array to writelength
- number of array elements to write- Throws:
IOException
- if there was an IO error writing to the output
-
write
SeeArrayDataOutput.write(float[], int, int)
for a contract of this method.- Parameters:
f
- array of single precision (32-bit) floating point values.start
- the index of the first element in the array to writelength
- number of array elements to write- Throws:
IOException
- if there was an IO error writing to the output
-
write
SeeArrayDataOutput.write(double[], int, int)
for a contract of this method.- Parameters:
d
- array of double-precision (64-bit) floating point values.start
- the index of the first element in the array to writelength
- number of array elements to write- Throws:
IOException
- if there was an IO error writing to the output
-
write
SeeArrayDataOutput.write(String[], int, int)
for a contract of this method.- Parameters:
str
- array of strings (containing ASCII characters only).start
- the index of the first element in the array to writelength
- number of array elements to write- Throws:
IOException
- if there was an IO error writing to the output
-
writeArray
Description copied from class:OutputEncoder
Writes the contents of a Java array to the output translating the data to the required binary representation. The argument may be any generic Java array, including heterogeneous arrays of arrays.- Specified by:
writeArray
in classOutputEncoder
- Parameters:
o
- the Java array, including heterogeneous arrays of arrays. Ifnull
nothing will be written to the output.- Throws:
IOException
- if there was an IO error writing to the outputIllegalArgumentException
- if the supplied object is not a Java array or if it contains Java types that are not supported by the decoder.- See Also:
-
putArray
Puts a Java array into the conversion buffer, but with no guarantee of flushing the conversion buffer to the underlying output. The argument may be any Java array of the types supported in FITS, including multi-dimensional arrays and heterogeneous arrays of arrays.
The caller may put multiple data object into the conversion buffer before eventually calling
OutputEncoder.flush()
to ensure that everything is written to the output. Note, the this call may flush the contents of the conversion buffer to the output if it needs more conversion space than what is avaiable.- Parameters:
o
- A Java array, including multi-dimensional arrays and heterogeneous arrays of arrays.- Throws:
IOException
- if there was an IO error while trying to flush the conversion buffer to the stream before all elements were converted.IllegalArgumentException
- if the argument is not an array, or if it is or contains an element that does not have a known FITS representation.- See Also:
-
computeSize
Returns the size of this object as the number of bytes in a FITS binary representation.- Parameters:
o
- the object- Returns:
- the number of bytes in the FITS binary representation of the object or 0 if the object has no FITS representation. (Also elements not known to FITS will count as 0 sized).
-