Package nom.tam.fits
Class FitsUtil
java.lang.Object
nom.tam.fits.FitsUtil
Static utility functions used throughout the FITS classes.
-
Method Summary
Modifier and TypeMethodDescriptionstatic int
addPadding
(int size) Deprecated.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.static InputStream
getURLStream
(URL url, int level) Gets and input stream for a given URL resource.static int
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 futurestatic void
pad
(ArrayDataOutput stream, long size, byte fill) Deprecated.(for internal use) Visibility may be reduced to private in the futurestatic int
padding
(int size) Deprecated.see Usepadding(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 anIOException
into aFitsException
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.
-
Method Details
-
addPadding
public static int addPadding(int size) Deprecated.useaddPadding(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
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 callString.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 convertmaxLen
- the max string length- Returns:
- Convert bytes to Strings, removing leading and trailing spaces from each entry.
-
findOffset
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
Gets and input stream for a given URL resource.- Parameters:
url
- the url to get the stream fromlevel
- 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
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
Deprecated.(for internal use) Visibility may be reduced to package level in the futureAdds the necessary amount of padding needed to complete the last FITS block.- Parameters:
stream
- stream to padsize
- 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
Deprecated.(for internal use) Visibility may be reduced to private in the futureAdds the necessary amount of padding needed to complete the last FITS block., usign the designated padding byte value.- Parameters:
stream
- stream to padsize
- 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 Usepadding(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.This method wraps anIOException
into aFitsException
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 outputoffset
- 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
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 Stringslen
- 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
-
addPadding(long)
instead.