pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1567406 - in /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel: common/PDStream.java font/PDCIDFontType2Font.java font/PDSimpleFont.java graphics/xobject/PDJpeg.java
Date Tue, 11 Feb 2014 21:46:19 GMT
Author: tilman
Date: Tue Feb 11 21:46:19 2014
New Revision: 1567406

URL: http://svn.apache.org/r1567406
Log:
PDFBOX-1909: Close open streams

Modified:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/PDStream.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDCIDFontType2Font.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDSimpleFont.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/xobject/PDJpeg.java

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/PDStream.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/PDStream.java?rev=1567406&r1=1567405&r2=1567406&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/PDStream.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/PDStream.java Tue Feb
11 21:46:19 2014
@@ -35,6 +35,7 @@ import org.apache.pdfbox.cos.COSStream;
 
 import org.apache.pdfbox.filter.Filter;
 import org.apache.pdfbox.filter.FilterManager;
+import org.apache.pdfbox.io.IOUtils;
 
 import org.apache.pdfbox.pdmodel.PDDocument;
 
@@ -249,21 +250,21 @@ public class PDStream implements COSObje
         InputStream is = stream.getFilteredStream();
         ByteArrayOutputStream os = new ByteArrayOutputStream();
         List<COSName> filters = getFilters();
-        COSName nextFilter = null;
         boolean done = false;
         for (int i = 0; i < filters.size() && !done; i++)
         {
-            os.reset();
-            nextFilter = filters.get(i);
+            COSName nextFilter = filters.get(i);
             if (stopFilters.contains(nextFilter.getName()))
             {
                 done = true;
-            } 
+            }
             else
             {
                 Filter filter = manager.getFilter(nextFilter);
                 filter.decode(is, os, stream, i);
+                IOUtils.closeQuietly(is);
                 is = new ByteArrayInputStream(os.toByteArray());
+                os.reset();
             }
         }
         return is;

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDCIDFontType2Font.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDCIDFontType2Font.java?rev=1567406&r1=1567405&r2=1567406&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDCIDFontType2Font.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDCIDFontType2Font.java
Tue Feb 11 21:46:19 2014
@@ -17,6 +17,7 @@
 package org.apache.pdfbox.pdmodel.font;
 
 import java.io.IOException;
+import java.io.InputStream;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -77,7 +78,9 @@ public class PDCIDFontType2Font extends 
             COSStream stream = (COSStream) map;
             try
             {
-                byte[] mapAsBytes = IOUtils.toByteArray(stream.getUnfilteredStream());
+                InputStream is = stream.getUnfilteredStream();
+                byte[] mapAsBytes = IOUtils.toByteArray(is);
+                IOUtils.closeQuietly(is);
                 int numberOfInts = mapAsBytes.length / 2;
                 cid2gid = new int[numberOfInts];
                 int offset = 0;

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDSimpleFont.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDSimpleFont.java?rev=1567406&r1=1567405&r2=1567406&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDSimpleFont.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDSimpleFont.java Tue
Feb 11 21:46:19 2014
@@ -285,7 +285,9 @@ public abstract class PDSimpleFont exten
                     COSStream encodingStream = (COSStream) encoding;
                     try
                     {
-                        cmap = parseCmap(null, encodingStream.getUnfilteredStream());
+                        InputStream is = encodingStream.getUnfilteredStream();
+                        cmap = parseCmap(null, is);
+                        IOUtils.closeQuietly(is);
                     }
                     catch (IOException exception)
                     {
@@ -351,7 +353,9 @@ public abstract class PDSimpleFont exten
             {
                 try
                 {
-                    toUnicodeCmap = parseCmap(resourceRootCMAP, ((COSStream) toUnicode).getUnfilteredStream());
+                    InputStream is = ((COSStream) toUnicode).getUnfilteredStream();
+                    toUnicodeCmap = parseCmap(resourceRootCMAP, is);
+                    IOUtils.closeQuietly(is);
                 }
                 catch (IOException exception)
                 {

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/xobject/PDJpeg.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/xobject/PDJpeg.java?rev=1567406&r1=1567405&r2=1567406&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/xobject/PDJpeg.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/xobject/PDJpeg.java
Tue Feb 11 21:46:19 2014
@@ -44,6 +44,7 @@ import javax.imageio.stream.ImageInputSt
 
 import org.apache.pdfbox.cos.COSDictionary;
 import org.apache.pdfbox.cos.COSName;
+import org.apache.pdfbox.io.IOUtils;
 import org.apache.pdfbox.pdmodel.PDDocument;
 import org.apache.pdfbox.pdmodel.common.PDStream;
 import org.apache.pdfbox.pdmodel.common.function.PDFunction;
@@ -299,11 +300,12 @@ public class PDJpeg extends PDXObjectIma
     {
         InputStream data = getPDStream().getPartiallyFilteredStream( DCT_FILTERS );
         byte[] buf = new byte[1024];
-        int amountRead = -1;
+        int amountRead;
         while( (amountRead = data.read( buf )) != -1 )
         {
             out.write( buf, 0, amountRead );
         }
+        IOUtils.closeQuietly(data);
     }
 
     private int getHeaderEndPos(byte[] imageAsBytes)



Mime
View raw message