Package nom.tam.util.type
Class ElementType<B extends Buffer>
java.lang.Object
nom.tam.util.type.ElementType<B>
- Type Parameters:
B
- the generic type of data buffer
- Direct Known Subclasses:
PrimitiveType
A base data element type in a FITS image or table column, with associated functions.
-
Field Summary
Modifier and TypeFieldDescriptionstatic final ElementType<Buffer>
The FITS representation of a boolean value in binary tablesstatic final ElementType<ByteBuffer>
The FITS representation of a single (signed) byte value in images and binary tablesstatic final ElementType<ByteBuffer>
The FITS representation of a Javachar
value in binary tablesstatic final int
Deprecated.(for internal use) It's visibility may be reduced to the package level in the future.static final ElementType<DoubleBuffer>
The FITS representation of a 64-bit double precison floating-point value in images and binary tablesstatic final ElementType<FloatBuffer>
The FITS representation of a 32-bit single precison floating-point value in images and binary tablesstatic final ElementType<IntBuffer>
The FITS representation of a 32-bit sined integer value in images and binary tablesstatic final ElementType<LongBuffer>
The FITS representation of a 64-bit sined integer value in images and binary tablesstatic final ElementType<ShortBuffer>
The FITS representation of a 16-bit sined integer value in images and binary tablesstatic final ElementType<Buffer>
The FITS representation of an ASCII string in binary tablesstatic final ElementType<Buffer>
Anything else for which we do not have a supported FITS representation -
Method Summary
Modifier and TypeMethodDescriptionvoid
appendBuffer
(B buffer, B dataToAppend) Appends data from one buffer to another.void
appendToByteBuffer
(ByteBuffer byteBuffer, B dataToAppend) Appends data from one buffer to a byte buffer.asTypedBuffer
(ByteBuffer buffer) Returns a typed view of a byte buffer, suitable for transacting elements of this type directly.int
bitPix()
Returns the integer BITPIX value to set in FITS headers for image HDUs of this element type.Returns the class of buffer that can be used to serialize or deserialize elements of this type.convertToByteBuffer
(Object array) Serializes a 1D Java array containing Java native elements into a buffer using the appropriate FITS representationstatic ElementType<Buffer>
forBitpix
(int bitPix) Returns the FITS element type that matches the specified BITPIX value exactly.static <B extends Buffer>
ElementType<B>forBuffer
(B b) Returns the FITS element type that can transact with the specified buffer type directly.static <B extends Buffer>
ElementType<B>Returns the FITS element type for a given Java typestatic ElementType<Buffer>
forDataID
(char type) Returns the Fits element type for a given Java array type letter.static ElementType<Buffer>
forNearestBitpix
(int bitPix) Returns the FITS element type that is nearest to the specified BITPIX value.final void
Gets all elements of an array from a bufferfinal void
Gets elements of an array from a buffer, starting at the beginning of the array.void
Gets elements of an array from a buffer, starting at the specified array index.final boolean
Deprecated.UseisVariableSize()
instead.boolean
is
(ElementType<? extends Buffer> other) Checks if this element type is the same as another.boolean
Checks if this type of element has a variable size, rather than a fixed sizenewArray
(int length) Creates a new 1D Java array for storing elements of this type.final B
newBuffer
(int length) Creates a new new buffer of the specified size for this type of elementsfinal B
newBuffer
(long length) Currently the same asnewBuffer(int)
, but in the future it may be used to implement large memory mapped buffers....Class<?>
Returns the Java primitive type corresponding to this element, if anyfinal void
Puts all elements from an array into the given bufferfinal void
Puts elements from an array into the given buffer, starting at the beginning of the arrayvoid
Puts elements from an array into the given buffer, starting at the specified array index.int
size()
Returns the number of bytes per elementsint
Returns the size of an element, provided it matches our element type.sliceBuffer
(B buffer) Returns a new typed buffer that starts at the the current position of the supplied typed buffer.char
type()
Returns the Java letter-code for this FITS element type.Returns a buffer for this element type by wrapping a suitable 1D array as its backing store.Class<?>
Returns the boxed Java type for this type of element.
-
Field Details
-
COPY_BLOCK_SIZE
public static final int COPY_BLOCK_SIZEDeprecated.(for internal use) It's visibility may be reduced to the package level in the future.Number of bytes to copy as a block- See Also:
-
BOOLEAN
The FITS representation of a boolean value in binary tables -
BYTE
The FITS representation of a single (signed) byte value in images and binary tables -
CHAR
The FITS representation of a Javachar
value in binary tables -
DOUBLE
The FITS representation of a 64-bit double precison floating-point value in images and binary tables -
FLOAT
The FITS representation of a 32-bit single precison floating-point value in images and binary tables -
INT
The FITS representation of a 32-bit sined integer value in images and binary tables -
LONG
The FITS representation of a 64-bit sined integer value in images and binary tables -
SHORT
The FITS representation of a 16-bit sined integer value in images and binary tables -
STRING
The FITS representation of an ASCII string in binary tables -
UNKNOWN
Anything else for which we do not have a supported FITS representation
-
-
Method Details
-
appendBuffer
Appends data from one buffer to another.- Parameters:
buffer
- the destination bufferdataToAppend
- the buffer containing the data segment to append.
-
appendToByteBuffer
Appends data from one buffer to a byte buffer.- Parameters:
byteBuffer
- the destination bufferdataToAppend
- the buffer containing the data segment to append.
-
asTypedBuffer
Returns a typed view of a byte buffer, suitable for transacting elements of this type directly.- Parameters:
buffer
- a byte buffer- Returns:
- the typed view of the byte buffer
-
bitPix
public int bitPix()Returns the integer BITPIX value to set in FITS headers for image HDUs of this element type.- Returns:
- The BITPIX value that FITS uses to specify images of this element type.
-
bufferClass
Returns the class of buffer that can be used to serialize or deserialize elements of this type.- Returns:
- The class of buffer that can transact elements of this type.
- See Also:
-
convertToByteBuffer
Serializes a 1D Java array containing Java native elements into a buffer using the appropriate FITS representation- Parameters:
array
- the 1D Java array of elements for this type- Returns:
- The FITS serialized representation as a buffer of bytes.
-
getArray
Gets all elements of an array from a buffer- Parameters:
buffer
- the typed buffer from which to retrieve elementsarray
- the 1D array of matching type- See Also:
-
getArray
Gets elements of an array from a buffer, starting at the beginning of the array.- Parameters:
buffer
- the typed buffer from which to retrieve elementsarray
- the 1D array of matching typelength
- the number of elements to fretrieve- See Also:
-
getArray
Gets elements of an array from a buffer, starting at the specified array index.- Parameters:
buffer
- the typed buffer from which to retrieve elementsarray
- the 1D array of matching typeoffset
- the array index of the first element to retrievelength
- the number of elements to fretrieve- See Also:
-
isVariableSize
public boolean isVariableSize()Checks if this type of element has a variable size, rather than a fixed size- Returns:
true
if this element may appear with different sizes in the FITS binary stream. Otherwisefalse
if it is always the same fixed size.- See Also:
-
individualSize
Deprecated.UseisVariableSize()
instead.- Returns:
true
if this type of element comes in all sizes, and the particular size of an obejct of this element type is specific to its instance. Or,false
for fixed-sized elements.
-
is
Checks if this element type is the same as another.- Parameters:
other
- Another element type- Returns:
true
if both element types are the same, otherwisefalse
.
-
newArray
Creates a new 1D Java array for storing elements of this type.- Parameters:
length
- the number of elements to store in the array- Returns:
- the Java array suitable for storing the elements, or
null
if the operation is not supported or possible. - See Also:
-
newBuffer
Creates a new new buffer of the specified size for this type of elements- Parameters:
length
- the number of elements in the buffer- Returns:
- a new buffer of the specified size for this type of elements
- See Also:
-
newBuffer
Currently the same asnewBuffer(int)
, but in the future it may be used to implement large memory mapped buffers....- Parameters:
length
- the number of elements in the buffer- Returns:
- a new buffer of the specified size for this type of elements, or
null
if the argument is beyond the supported range - Throws:
IllegalArgumentException
- if the length is larger than what can be supported.- See Also:
-
primitiveClass
Returns the Java primitive type corresponding to this element, if any- Returns:
- the Java primitive type that corresponds to this element, or
null
if there is no primitive type equivalent to this FITS element type. - See Also:
-
putArray
Puts all elements from an array into the given buffer- Parameters:
buffer
- the typed buffer in which to put elementsarray
- the 1D array of matching type- Since:
- 1.18
- See Also:
-
putArray
Puts elements from an array into the given buffer, starting at the beginning of the array- Parameters:
buffer
- the typed buffer in which to put elementsarray
- the 1D array of matching typelength
- the number of elements to put into the buffer- Since:
- 1.18
- See Also:
-
putArray
Puts elements from an array into the given buffer, starting at the specified array index.- Parameters:
buffer
- the typed buffer in which to put elementsarray
- the 1D array of matching typeoffset
- the array index of the first element to put into the bufferlength
- the number of elements to put into the buffer- Since:
- 1.18
- See Also:
-
size
public int size()Returns the number of bytes per elements- Returns:
- the number of bytes each element of this type occupies in FITS binary representation
- See Also:
-
size
Returns the size of an element, provided it matches our element type.- Parameters:
instance
- the object to calculate the size- Returns:
size()
if the object is a primitive or boxed java type that matches this element type, or 0 if the object isnull
.- Throws:
IllegalArgumentException
- if the object is not of the type expected by this class.- See Also:
-
sliceBuffer
Returns a new typed buffer that starts at the the current position of the supplied typed buffer. SeeBuffer.slice()
for the contract on slices.- Parameters:
buffer
- the buffer from which to create the new slice- Returns:
- A new buffer of the same type as the argument, that begins at the current position of the original
buffer, or
null
if the slicing is not possuble or not implemented. - See Also:
-
type
public char type()Returns the Java letter-code for this FITS element type. For example Javalong
would be type 'J' since 1Dlong[]
arrays report as[J
by Java.- Returns:
- the boxed Java type for this FITS element type.
- See Also:
-
wrap
Returns a buffer for this element type by wrapping a suitable 1D array as its backing store.- Parameters:
array
- the matching 1D array for this type to serve as the backing store of the buffer. Changes to the array will be visible through the buffer and vice versa.- Returns:
- A new buffer for this type of element that uses the specified array as its backing store.
-
wrapperClass
Returns the boxed Java type for this type of element.- Returns:
- the boxed Java type that corresponds to this type of element.
- See Also:
-
forDataID
Returns the Fits element type for a given Java array type letter. For exampleLONG
is returned for 'J' since Java denoteslong[]
arrays as[J
in shorthand.- Parameters:
type
- the letter code used for denoting java arrays of a given type in shorthand- Returns:
- the matching FITS element type.
- See Also:
-
forClass
Returns the FITS element type for a given Java type- Type Parameters:
B
- The generic type of buffer for the FITS element type- Parameters:
clazz
- The Java primitive or boxed type for the corresponding element, or else the buffer class that it uses.- Returns:
- The matching FITS element type.
- See Also:
-
forBuffer
Returns the FITS element type that can transact with the specified buffer type directly.- Type Parameters:
B
- the generic type of buffer- Parameters:
b
- a typed buffer instance- Returns:
- the FITS element type that goes with the specified typed buffer
- See Also:
-
forBitpix
Returns the FITS element type that matches the specified BITPIX value exactly.- Parameters:
bitPix
- the BITPIX value that FITS uses to specify the element type for images.- Returns:
- The matching FITS element type, or
null
if there is no matching FITS element type. - See Also:
-
forNearestBitpix
Returns the FITS element type that is nearest to the specified BITPIX value. This method can be used to guess what the element type may be when the BITPIX value is not strictly to specification in the FITS header.- Parameters:
bitPix
- the BITPIX value that FITS uses to specify the element type for images.- Returns:
- The FITS element type that is closest to the specified value, or
UNKNOWN
if the specified values is not near any known BITPIX type. - See Also:
-