View Javadoc
1   package nom.tam.fits.compress;
2   
3   /*
4    * #%L
5    * nom.tam FITS library
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.IOException;
35  import java.io.InputStream;
36  
37  import nom.tam.fits.FitsException;
38  
39  /**
40   * (<i>for internal use</i>) Input stream decompression interface.
41   */
42  public interface ICompressProvider {
43  
44      /**
45       * Decompresses data from an input stream.
46       * 
47       * @param in
48       *            the input stream containing compressed data
49       * @return a new input stream containing the decompressed data
50       * @throws IOException
51       *             if there was an IO error while accessing the input stream
52       * @throws FitsException
53       *             if the decompression cannot be performed for some reason that
54       *             is not related to the input per se.
55       */
56      InputStream decompress(InputStream in) throws IOException, FitsException;
57  
58      /**
59       * Returns the priority of this method. {@link CompressionManager} will use
60       * this to select the 'best' compression class when multiple compression
61       * classes can provide decompression support for a given input stream.
62       * Claases that have a higher priority will be preferred.
63       * 
64       * @return the priority of this decompression method vs similar other
65       *         compression methods that may be avaialble.
66       * @see CompressionManager
67       */
68      int priority();
69  
70      /**
71       * Checks if this compression method can support the magic integer number
72       * that is used to identify the type of compression at the beginning of
73       * compressed files, and is stored as the first 2 bytes of compressed data.
74       * 
75       * @param byte1
76       *            the first byte of the compressed file
77       * @param byte2
78       *            the second byte of the compressed file
79       * @return <code>true</code> if this class can be used to decompress the
80       *         given file, or else <code>false</code>.
81       */
82      boolean provides(int byte1, int byte2);
83  }