coolshou / thumbnailator

Automatically exported from code.google.com/p/thumbnailator
Other
0 stars 0 forks source link

Produced Files Being "Locked" #17

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I'm using something like the following piece of code:

<code>File source = new File("C;\test.png");
File dest = new File("C:\test_thumb.png");
BufferedImage buffered = ImageIO.read(source);
Thumbnails.of(source).forceSize(150, 150).toFile(dest);</code>

This is being run as part of an app running on Tomcat.  The thumbnail is 
created successfully but it appears to be locked in some way.  Although Windows 
will show me a thumbnail of the image, when I try to open the file in a variety 
of programs then the image is unreadable.  If I stop Tomcat, then the file 
becomes readable.

It appears that something is keeping some form of lock open on the file.  If I 
get a chance, I'll dive into the code and see if I can spot what.

This is on Windows, Java 1.6 & using Thumbnailator 0.3.7 (latest at the time of 
writing).

Original issue reported on code.google.com by Lee.Theo...@gmail.com on 27 Jul 2011 at 3:28

GoogleCodeExporter commented 9 years ago
I'm guessing the problem is the FileOutputStream on line 342 of FileImageSink.  
It's being created in the try block but never closed.  I believe this will mean 
that the stream will be left open until it's garbage collected (in my case, 
when I shut down Tomcat).

Original comment by Lee.Theo...@gmail.com on 27 Jul 2011 at 3:38

GoogleCodeExporter commented 9 years ago
Thank you for reporting this issue.

The issue has been reproduced. The problem does indeed appear to be caused by 
the `FileOutputStream` not being closed after the thumbnail is written.

I find this to be a fairly serious issue and expect to get a fix out within 48 
hours.

Once again, thank you for spending the time to investigate the issue, and sorry 
for the inconvenience.

Original comment by coobird...@gmail.com on 28 Jul 2011 at 3:18

GoogleCodeExporter commented 9 years ago

Original comment by coobird...@gmail.com on 28 Jul 2011 at 3:19

GoogleCodeExporter commented 9 years ago
The issue has been resolved in Thumbnailator 0.3.8.

---------

A follow up on `comment 1`:

  > I believe this will mean that the stream will be left open until it's garbage collected (in my case, when I shut down Tomcat).

I can confirm that under Thumbnailator 0.3.7, the thumbnail image file does 
appear to get closed when garbage collection takes place.

In order to verify this, I tried making a thumbnail using `toFile`, and 
directly afterward called `System.gc` and tried opening the thumbnail file from 
another application. The file opened successfully.

Original comment by coobird...@gmail.com on 30 Jul 2011 at 5:04