Package nom.tam.fits

Class FitsUtil

java.lang.Object
nom.tam.fits.FitsUtil

public final class FitsUtil extends Object
Static utility functions used throughout the FITS classes.
  • Method Summary

    Modifier and Type
    Method
    Description
    static int
    addPadding(int size)
    Deprecated.
    use addPadding(long) instead.
    static long
    addPadding(long size)
    Calculates the amount of padding needed to complete the last FITS block at the specified current size.
    static String[]
    byteArrayToStrings(byte[] bytes, int maxLen)
    Deprecated.
    (for internal use) No longer used internally, will be removed in the future.
    static long
    Deprecated.
    (for internal use) Visibility may be reduced to the package level in the future.
    getURLStream(URL url, int level)
    Gets and input stream for a given URL resource.
    static int
    maxLength(String[] strings)
    Deprecated.
    (for internal use) No longer used internally, may be removed in the future.
    static void
    pad(ArrayDataOutput stream, long size)
    Deprecated.
    (for internal use) Visibility may be reduced to package level in the future
    static void
    pad(ArrayDataOutput stream, long size, byte fill)
    Deprecated.
    (for internal use) Visibility may be reduced to private in the future
    static int
    padding(int size)
    Deprecated.
    see Use padding(long) instead.
    static int
    padding(long size)
    Calculated the amount of padding we need to add given the current size of a FITS file (under construction)
    static void
    reposition(FitsIO o, long offset)
    Deprecated.
    This method wraps an IOException into a FitsException for no good reason really.
    static byte[]
    stringsToByteArray(String[] stringArray, int len)
    Deprecated.
    (for internal use) Visibility may be reduced to package level in the future.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • addPadding

      public static int addPadding(int size)
      Deprecated.
      use addPadding(long) instead. Calculates the amount of padding needed to complete the last FITS block at the specified current size.
      Parameters:
      size - the current size.
      Returns:
      Total size of blocked FITS element, using e.v. padding to fits block size.
    • addPadding

      public static long addPadding(long size)
      Calculates the amount of padding needed to complete the last FITS block at the specified current size.
      Parameters:
      size - the current size.
      Returns:
      Total size of blocked FITS element, using e.v. padding to fits block size.
      See Also:
    • byteArrayToStrings

      public static String[] byteArrayToStrings(byte[] bytes, int maxLen)
      Deprecated.
      (for internal use) No longer used internally, will be removed in the future.
      Converts a FITS byte sequence to a Java string array, triming spaces at the heads and tails of each element. While FITS typically considers leading spaces significant, this library has been removing them from regularly shaped string arrays for a very long time, apparently based on request by users then... Even though it seems like a bad choice, since users could always call String.trim() if they needed to, we cannot recover the leading spaces once the string was trimmed. At this point we have no real choice but to continue the tradition, lest we want to break exising applications, which may rely on this behavior.
      Parameters:
      bytes - byte array to convert
      maxLen - the max string length
      Returns:
      Convert bytes to Strings, removing leading and trailing spaces from each entry.
    • findOffset

      public static long findOffset(Closeable o)
      Deprecated.
      (for internal use) Visibility may be reduced to the package level in the future.
      Gets the file offset for the given IO resource.
      Parameters:
      o - the stream to get the position
      Returns:
      The offset from the beginning of file (if random accessible), or -1 otherwise.
    • getURLStream

      public static InputStream getURLStream(URL url, int level) throws IOException
      Gets and input stream for a given URL resource.
      Parameters:
      url - the url to get the stream from
      level - max levels of redirection
      Returns:
      Get a stream to a URL accommodating possible redirections. Note that if a redirection request points to a different protocol than the original request, then the redirection is not handled automatically.
      Throws:
      IOException - if the operation failed
    • maxLength

      public static int maxLength(String[] strings)
      Deprecated.
      (for internal use) No longer used internally, may be removed in the future.
      Returns the maximum string length in an array.
      Parameters:
      strings - array of strings to check
      Returns:
      the maximum length of string in an array.
    • pad

      public static void pad(ArrayDataOutput stream, long size) throws FitsException
      Deprecated.
      (for internal use) Visibility may be reduced to package level in the future
      Adds the necessary amount of padding needed to complete the last FITS block.
      Parameters:
      stream - stream to pad
      size - the current size of the stream (total number of bytes written to it since the beginning of the FITS).
      Throws:
      FitsException - if the operation failed
      See Also:
    • pad

      public static void pad(ArrayDataOutput stream, long size, byte fill) throws FitsException
      Deprecated.
      (for internal use) Visibility may be reduced to private in the future
      Adds the necessary amount of padding needed to complete the last FITS block., usign the designated padding byte value.
      Parameters:
      stream - stream to pad
      size - the current size of the stream (total number of bytes written to it since the beginning of the FITS).
      fill - the byte value to use for the padding
      Throws:
      FitsException - if the operation failed
      See Also:
    • padding

      public static int padding(int size)
      Deprecated.
      see Use padding(long) instead.
      Parameters:
      size - the size without padding
      Returns:
      How many bytes are needed to fill a 2880 block?
    • padding

      public static int padding(long size)
      Calculated the amount of padding we need to add given the current size of a FITS file (under construction)
      Parameters:
      size - the current size of our FITS file before the padding
      Returns:
      the number of bytes of padding we need to add at the end to complete the FITS block.
      See Also:
    • reposition

      @Deprecated public static void reposition(FitsIO o, long offset) throws FitsException
      Deprecated.
      This method wraps an IOException into a FitsException for no good reason really. A revision of the API could reduce the visibility of this method, and/or procees the underlying exception instead.
      Attempts to reposition a FITS input ot output. The call will succeed only if the underlying input or output is random accessible. Othewise, an exception will be thrown.
      Parameters:
      o - the FITS input or output
      offset - the offset to position it to.
      Throws:
      FitsException - if the underlying input/output is not random accessible or if the requested position is invalid.
    • stringsToByteArray

      public static byte[] stringsToByteArray(String[] stringArray, int len)
      Deprecated.
      (for internal use) Visibility may be reduced to package level in the future.
      Convert an array of Strings to bytes. padding (with 0x00) or truncating as necessary to provide the expected length.
      Parameters:
      stringArray - the array with Strings
      len - the number of bytes used for each string element. The string will be truncated ot padded as necessary to fit into that size.
      Returns:
      the resulting bytes