tika-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mikemcc...@apache.org
Subject svn commit: r1300135 - in /tika/trunk: CHANGES.txt tika-parsers/src/main/java/org/apache/tika/parser/image/ImageParser.java
Date Tue, 13 Mar 2012 13:59:50 GMT
Author: mikemccand
Date: Tue Mar 13 13:59:50 2012
New Revision: 1300135

URL: http://svn.apache.org/viewvc?rev=1300135&view=rev
Log:
TIKA-875: fix file handle leak in ImageParser

Modified:
    tika/trunk/CHANGES.txt
    tika/trunk/tika-parsers/src/main/java/org/apache/tika/parser/image/ImageParser.java

Modified: tika/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/tika/trunk/CHANGES.txt?rev=1300135&r1=1300134&r2=1300135&view=diff
==============================================================================
--- tika/trunk/CHANGES.txt (original)
+++ tika/trunk/CHANGES.txt Tue Mar 13 13:59:50 2012
@@ -1,15 +1,14 @@
-Apache Tika Change Log
-======================
-
- * Tika: parseToString now lets you specify the max string length
-   per-call, in addition to per-Tika-instance. (TIKA-870)
-
 Release 1.2 - Current Development
 ---------------------------------
 
+  * Tika: parseToString now lets you specify the max string length
+    per-call, in addition to per-Tika-instance. (TIKA-870)
+
   * Tika now has the ability to detect FITS (Flexible Image Transport System) 
     files (TIKA-874).
 
+  * Images: Fixed file handle leak in ImageParser. (TIKA-875)
+
 Release 1.1 - 3/7/2012
 ---------------------------------
 

Modified: tika/trunk/tika-parsers/src/main/java/org/apache/tika/parser/image/ImageParser.java
URL: http://svn.apache.org/viewvc/tika/trunk/tika-parsers/src/main/java/org/apache/tika/parser/image/ImageParser.java?rev=1300135&r1=1300134&r2=1300135&view=diff
==============================================================================
--- tika/trunk/tika-parsers/src/main/java/org/apache/tika/parser/image/ImageParser.java (original)
+++ tika/trunk/tika-parsers/src/main/java/org/apache/tika/parser/image/ImageParser.java Tue
Mar 13 13:59:50 2012
@@ -28,6 +28,7 @@ import javax.imageio.IIOException;
 import javax.imageio.ImageIO;
 import javax.imageio.ImageReader;
 import javax.imageio.metadata.IIOMetadata;
+import javax.imageio.stream.ImageInputStream;
 
 import org.apache.tika.exception.TikaException;
 import org.apache.tika.io.CloseShieldInputStream;
@@ -81,17 +82,24 @@ public class ImageParser extends Abstrac
                     ImageIO.getImageReadersByMIMEType(type);
                 if (iterator.hasNext()) {
                     ImageReader reader = iterator.next();
-                    reader.setInput(ImageIO.createImageInputStream(
-                            new CloseShieldInputStream(stream)));
-                    
-                    metadata.set(Metadata.IMAGE_WIDTH, Integer.toString(reader.getWidth(0)));
-                    metadata.set(Metadata.IMAGE_LENGTH, Integer.toString(reader.getHeight(0)));
-                    metadata.set("height", Integer.toString(reader.getHeight(0)));
-                    metadata.set("width", Integer.toString(reader.getWidth(0)));
-
-                    loadMetadata(reader.getImageMetadata(0), metadata);
-
-                    reader.dispose();
+                    try {
+                        ImageInputStream imageStream = ImageIO.createImageInputStream(
+                                new CloseShieldInputStream(stream));
+                        try {
+                            reader.setInput(imageStream);
+                            
+                            metadata.set(Metadata.IMAGE_WIDTH, Integer.toString(reader.getWidth(0)));
+                            metadata.set(Metadata.IMAGE_LENGTH, Integer.toString(reader.getHeight(0)));
+                            metadata.set("height", Integer.toString(reader.getHeight(0)));
+                            metadata.set("width", Integer.toString(reader.getWidth(0)));
+
+                            loadMetadata(reader.getImageMetadata(0), metadata);
+                        } finally {
+                            imageStream.close();
+                        }
+                    } finally {
+                        reader.dispose();
+                    }
                 }
                 
                 // Translate certain Metadata tags from the ImageIO



Mime
View raw message