View Javadoc
1   package nom.tam.fits;
2   
3   /*-
4    * #%L
5    * nom.tam.fits
6    * %%
7    * Copyright (C) 1996 - 2024 nom-tam-fits
8    * %%
9    * This is free and unencumbered software released into the public domain.
10   * 
11   * Anyone is free to copy, modify, publish, use, compile, sell, or
12   * distribute this software, either in source code form or as a compiled
13   * binary, for any purpose, commercial or non-commercial, and by any
14   * means.
15   * 
16   * In jurisdictions that recognize copyright laws, the author or authors
17   * of this software dedicate any and all copyright interest in the
18   * software to the public domain. We make this dedication for the benefit
19   * of the public at large and to the detriment of our heirs and
20   * successors. We intend this dedication to be an overt act of
21   * relinquishment in perpetuity of all present and future rights to this
22   * software under copyright law.
23   * 
24   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25   * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26   * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
27   * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
28   * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
29   * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
30   * OTHER DEALINGS IN THE SOFTWARE.
31   * #L%
32   */
33  
34  import java.io.PrintStream;
35  
36  import nom.tam.fits.header.Standard;
37  
38  import static nom.tam.fits.header.Standard.XTENSION;
39  
40  import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
41  
42  /**
43   * A HDU that holds a type of data we don't recognise. We can still access that data in its raw binary form, and the
44   * user can interpret the headers to make sense of particular but not (yet) supported FITS HDU types.
45   * 
46   * @see UndefinedData
47   */
48  public class UndefinedHDU extends BasicHDU<UndefinedData> {
49  
50      @Override
51      protected String getCanonicalXtension() {
52          return "UNKNOWN";
53      }
54  
55      /**
56       * @deprecated               (<i>for internal use</i>) Will reduce visibility in the future
57       *
58       * @return                   Encapsulate an object as an UndefinedHDU.
59       *
60       * @param      o             the object to encapsulate
61       *
62       * @throws     FitsException if the operation failed
63       */
64      @Deprecated
65      public static UndefinedData encapsulate(Object o) throws FitsException {
66          return new UndefinedData(o);
67      }
68  
69      /**
70       * Checks if we can use the following object as in an Undefined FITS block. Only <code>byte[]</code> arrays can be
71       * represented in undefined HDUs.
72       *
73       * @deprecated   (<i>for internal use</i>) Will reduce visibility in the future
74       *
75       * @param      o a data object
76       *
77       * @return       <code>true</code> if the object is a raw <code>byte[]</code> array, otherwise <code>false</code>.
78       *                   We cannot wrap arbitrary data objects since we do not have a generic recipe for converting
79       *                   these into binary form.
80       */
81      @SuppressFBWarnings(value = "HSM_HIDING_METHOD", justification = "deprecated existing method, kept for compatibility")
82      @Deprecated
83      public static boolean isData(Object o) {
84          return o instanceof byte[];
85      }
86  
87      /**
88       * Checks if the header is for a HDU we don't really know how to handle. We can still retrieve and store the binary
89       * tata of the HDU as a raw <code>byte[]</code> image.
90       *
91       * @deprecated     (<i>for internal use</i>) Will reduce visibility in the future
92       *
93       * @param      hdr header to check.
94       *
95       * @return         <CODE>true</CODE> if this HDU has a valid header.
96       */
97      @SuppressFBWarnings(value = "HSM_HIDING_METHOD", justification = "deprecated existing method, kept for compatibility")
98      @Deprecated
99      public static boolean isHeader(Header hdr) {
100         if (ImageHDU.isHeader(hdr)) {
101             return false;
102         }
103         if (BinaryTableHDU.isHeader(hdr)) {
104             return false;
105         }
106         if (AsciiTableHDU.isHeader(hdr)) {
107             return false;
108         }
109         return hdr.containsKey(Standard.XTENSION);
110     }
111 
112     /**
113      * Prepares a data object into which the actual data can be read from an input subsequently or at a later time.
114      *
115      * @deprecated               (<i>for internal use</i>) Will reduce visibility in the future
116      *
117      * @param      hdr           The FITS header that describes the data
118      *
119      * @return                   A data object that support reading content from a stream.
120      *
121      * @throws     FitsException if the data could not be prepared to prescriotion.
122      */
123     @Deprecated
124     public static UndefinedData manufactureData(Header hdr) throws FitsException {
125         return new UndefinedData(hdr);
126     }
127 
128     /**
129      * @deprecated               (<i>for internal use</i>) Will reduce visibility in the future
130      *
131      * @return                   Create a header that describes the given image data.
132      *
133      * @param      d             The image to be described.
134      *
135      * @throws     FitsException if the object does not contain valid image data.
136      */
137     @Deprecated
138     public static Header manufactureHeader(Data d) throws FitsException {
139 
140         Header h = new Header();
141         d.fillHeader(h);
142 
143         return h;
144     }
145 
146     /**
147      * Build an image HDU using the supplied data.
148      * 
149      * @deprecated   (<i>for internal use</i>) Its visibility should be reduced to package level in the future.
150      *
151      * @param      h the header for this HDU
152      * @param      d the data used to build the image.
153      */
154     public UndefinedHDU(Header h, UndefinedData d) {
155         super(h, d);
156     }
157 
158     @Override
159     public void info(PrintStream stream) {
160         stream.println("  Unhandled/Undefined/Unknown Type");
161         stream.println("  XTENSION=" + myHeader.getStringValue(XTENSION).trim());
162         stream.println("  Apparent size:" + myData.getTrueSize());
163     }
164 }