We're Hiring!

Closing of the IFormatReader object.

General and open developer discussion about using OMERO APIs from C++, Java, Python, Matlab and more! Please new questions at https://forum.image.sc/tags/omero
Please note:
Historical discussions about OMERO. Please look for and ask new questions at https://forum.image.sc/tags/omero

If you are having trouble with custom code, please provide a link to a public repository, ideally GitHub.

Closing of the IFormatReader object.

Postby n_biocoder » Fri Apr 02, 2010 7:27 am

The following code opens a file using IFormatReader, closes all the objects and tries to delete the file.

Code: Select all
/* open image reader */
ImageReader imgReader = new ImageReader();
IFormatReader formatReader = imgReader.getReader("file.tif");
formatReader.setId("file.tif");
BufferedImageReader bufferedImageReader = new BufferedImageReader(formatReader);
BufferedImage buffImage = bufferedImageReader.openThumbImage(0);

/* close image reader */
imgReader.close();
imgReader = null;
formatReader.close();
formatReader = null;

/* delete file */
File filenameObj = new File("file.tif");
boolean boolFile = filenameObj.delete();


The delete file will not work. I think its because of line 135 (Location.getHandle(id);) in ImageReader in the public IFormatReader getReader(String id) method. It returns an IRandomAccess which needs to be closed. When i replace that code with the following it seems to work fine.

Code: Select all
IRandomAccess canReadID = Location.getHandle(id);
canReadID.close();


I dont know if this change has any side effects furthur on. Could someone comment on the same? If its a valid issue, maybe it could be fixed next release.

~Thanks
n_biocoder
 
Posts: 4
Joined: Tue Mar 30, 2010 5:49 pm

Re: Closing of the IFormatReader object.

Postby mlinkert » Mon Apr 05, 2010 9:01 pm

Hi,

This problem was fixed in SVN revision 6024, which you can view here:

https://skyking.microscopy.wisc.edu/tra ... geset/6024

You can test the fix by updating to a recent trunk or daily build of Bio-Formats.

Regards,
-Melissa
User avatar
mlinkert
Team Member
 
Posts: 353
Joined: Fri May 29, 2009 2:12 pm
Location: Southwest Wisconsin

Re: Closing of the IFormatReader object.

Postby n_biocoder » Thu Apr 08, 2010 7:25 pm

Hi,

There is another change i would suggest to solve a similar problem when we open and try to delete jpg images. I made this change in the loci.formats.in.ImageIOReader. The following code on Line 92 locks the file if we dont call close functions on DataInputStream and RandomAccessInputStream objects.
Code: Select all
BufferedImage img =
      ImageIO.read(new DataInputStream(new RandomAccessInputStream(currentId)));


After closing those objects it seemed to work ok.
Code: Select all
RandomAccessInputStream rIn = new RandomAccessInputStream(currentId);
DataInputStream dIn = new DataInputStream(rIn);
BufferedImage img = ImageIO.read(dIn);
rIn.close();
dIn.close();


~Thanks
n_biocoder
 
Posts: 4
Joined: Tue Mar 30, 2010 5:49 pm

Re: Closing of the IFormatReader object.

Postby mlinkert » Thu Apr 08, 2010 9:30 pm

Hi,

Thank you for pointing out this problem. SVN revision 6107 (https://skyking.microscopy.wisc.edu/tra ... geset/6107) fixes this and a few similar problems.

Regards,
-Melissa
User avatar
mlinkert
Team Member
 
Posts: 353
Joined: Fri May 29, 2009 2:12 pm
Location: Southwest Wisconsin


Return to Developer Discussion

Who is online

Users browsing this forum: Google [Bot] and 0 guests