Posted by
Gregory Jefferis on
URL: http://imagej.273.s1.nabble.com/Open-gzipped-FITS-image-files-tp3699348p3699350.html
Hi Leonard,
I forgot the first version I sent needs an extra library for the zlib
encoding that you don't want anyway. Here is the very basic version I used
to use which should do just what you want. In the past I have added it as a
private class within the body of an existing class like the Biorad_Reader
it should work fine in the same way with the FITS_Reader. Best,
Greg.
PS watch line breaks!
--
class FlexibleFileOpener extends FileOpener {
// private class which determines if the file is gzipped or not
// and adds a GZIPInputStream if required
public FlexibleFileOpener(FileInfo fi) {
super(fi);
}
public InputStream createInputStream(FileInfo fi) throws IOException,
MalformedURLException {
// use the method in the FileOpener class to generate an input
stream
InputStream is=super.createInputStream(fi);
if (is!=null & fi.fileName.toLowerCase().endsWith(".gz")) {
// then stick a GZIPInputStream on top of it!
return new GZIPInputStream(is);
} else {
// Just return plain input stream
return is;
}
}
}
--
On 23/5/07 22:44, "Gregory Jefferis" <
[hidden email]> wrote:
> Dear Leonard,
>
> I have done this for various readers using the attached code. It has more
> functionality than you want but it might be useful.
>
> Just replace any FileOpener object in the FITS opener plugin with
> FlexibleFileOpener and you are there (it will automatically add a GZFileOpener
> if the file name ends in .gz). Something like this
>
> fo = new FlexibleFileOpener(fi);
> imp = fo.open(false);
>
> Feel free to contact me if you would like more assistance. I may see if Wayne
> would be interested in adding this functionality to ImageJ.
>
> Best wishes,
>
> Greg.
>
> The additional functionality allows you to use it to open ZLIB compressed data
> (gzip without the full header) and to specify an offset for the start of the
> compressed block in the file and a separate offset for the start of the image
> data within the compressed block.
>
>
>
>> Date: Tue, 22 May 2007 10:58:49 -0600
>> From: Leonard Sitongia <
[hidden email]>
>> Subject: Open gzipped FITS image files
>>
>> Hi,
>>
>> I'd like to be able to read gzipped FITS image files, decompressing the files
>> on the fly. Is this already possible (I don't see it)? If not, then it
>> seems like this would be pretty easy to add to the code, by wrapping
>> something like "new GZIPInputStream()" around the existing input stream (with
>> the necessary logic to check for a compressed file, and such).
>>
>> Has this been done/can this be done?
>>
>> Thanks!
>> --
>> ==Leonard E. Sitongia
>> High Altitude Observatory
>> National Center for Atmospheric Research
>> P.O. Box 3000 Boulder CO 80307 USA
>>
[hidden email] voice: (303)497-2454 fax: (303)497-1804
>>
>> -------------
>
>
--
Gregory Jefferis, PhD and:
Research Fellow
Department of Zoology St John's College
University of Cambridge Cambridge
Downing Street CB2 1TP
Cambridge, CB2 3EJ
United Kingdom
Lab Tel: +44 (0)1223 336683 Office: +44 (0)1223 339899
Lab Fax: +44 (0)1223 336676
[hidden email]
http://www.zoo.cam.ac.uk/zoostaff/jefferis.htmlhttp://www.neuroscience.cam.ac.uk/directory/profile.php?gsxej2http://flybrain.stanford.edu