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  /**
41   * 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
42   * user can interpret the headers to make sense of particular but not (yet) supported FITS HDU types.
43   * 
44   * @see UndefinedData
45   */
46  public class UndefinedHDU extends BasicHDU<UndefinedData> {
47  
48      @Override
49      protected String getCanonicalXtension() {
50          return "UNKNOWN";
51      }
52  
53      /**
54       * @deprecated               (<i>for internal use</i>) Will reduce visibility in the future
55       *
56       * @return                   Encapsulate an object as an UndefinedHDU.
57       *
58       * @param      o             the object to encapsulate
59       *
60       * @throws     FitsException if the operation failed
61       */
62      @Deprecated
63      public static UndefinedData encapsulate(Object o) throws FitsException {
64          return new UndefinedData(o);
65      }
66  
67      /**
68       * Checks if we can use the following object as in an Undefined FITS block. Only <code>byte[]</code> arrays can be
69       * represented in undefined HDUs.
70       *
71       * @deprecated   (<i>for internal use</i>) Will reduce visibility in the future
72       *
73       * @param      o a data object
74       *
75       * @return       <code>true</code> if the object is a raw <code>byte[]</code> array, otherwise <code>false</code>.
76       *                   We cannot wrap arbitrary data objects since we do not have a generic recipe for converting
77       *                   these into binary form.
78       */
79      @Deprecated
80      public static boolean isData(Object o) {
81          return o instanceof byte[];
82      }
83  
84      /**
85       * Checks if the header is for a HDU we don't really know how to handle. We can still retrieve and store the binary
86       * tata of the HDU as a raw <code>byte[]</code> image.
87       *
88       * @deprecated     (<i>for internal use</i>) Will reduce visibility in the future
89       *
90       * @param      hdr header to check.
91       *
92       * @return         <CODE>true</CODE> if this HDU has a valid header.
93       */
94      @Deprecated
95      public static boolean isHeader(Header hdr) {
96          if (ImageHDU.isHeader(hdr)) {
97              return false;
98          }
99          if (BinaryTableHDU.isHeader(hdr)) {
100             return false;
101         }
102         if (AsciiTableHDU.isHeader(hdr)) {
103             return false;
104         }
105         return hdr.containsKey(Standard.XTENSION);
106     }
107 
108     /**
109      * Prepares a data object into which the actual data can be read from an input subsequently or at a later time.
110      *
111      * @deprecated               (<i>for internal use</i>) Will reduce visibility in the future
112      *
113      * @param      hdr           The FITS header that describes the data
114      *
115      * @return                   A data object that support reading content from a stream.
116      *
117      * @throws     FitsException if the data could not be prepared to prescriotion.
118      */
119     @Deprecated
120     public static UndefinedData manufactureData(Header hdr) throws FitsException {
121         return new UndefinedData(hdr);
122     }
123 
124     /**
125      * @deprecated               (<i>for internal use</i>) Will reduce visibility in the future
126      *
127      * @return                   Create a header that describes the given image data.
128      *
129      * @param      d             The image to be described.
130      *
131      * @throws     FitsException if the object does not contain valid image data.
132      */
133     @Deprecated
134     public static Header manufactureHeader(Data d) throws FitsException {
135 
136         Header h = new Header();
137         d.fillHeader(h);
138 
139         return h;
140     }
141 
142     /**
143      * Build an image HDU using the supplied data.
144      * 
145      * @deprecated   (<i>for internal use</i>) Its visibility should be reduced to package level in the future.
146      *
147      * @param      h the header for this HDU
148      * @param      d the data used to build the image.
149      */
150     public UndefinedHDU(Header h, UndefinedData d) {
151         super(h, d);
152     }
153 
154     @Override
155     public void info(PrintStream stream) {
156         stream.println("  Unhandled/Undefined/Unknown Type");
157         stream.println("  XTENSION=" + myHeader.getStringValue(XTENSION).trim());
158         stream.println("  Apparent size:" + myData.getTrueSize());
159     }
160 }