pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1854869 - /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/PDFStreamEngine.java
Date Tue, 05 Mar 2019 20:08:28 GMT
Author: tilman
Date: Tue Mar  5 20:08:28 2019
New Revision: 1854869

URL: http://svn.apache.org/viewvc?rev=1854869&view=rev
Log:
PDFBOX-4071: close input stream

Modified:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/PDFStreamEngine.java

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/PDFStreamEngine.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/PDFStreamEngine.java?rev=1854869&r1=1854868&r2=1854869&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/PDFStreamEngine.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/PDFStreamEngine.java
Tue Mar  5 20:08:28 2019
@@ -487,24 +487,27 @@ public abstract class PDFStreamEngine
     private void processStreamOperators(PDContentStream contentStream) throws IOException
     {
         List<COSBase> arguments = new ArrayList<>();
-        PDFStreamParser parser = new PDFStreamParser(contentStream.getContents());
-        Object token = parser.parseNextToken();
-        while (token != null)
+        try (InputStream is = contentStream.getContents())
         {
-            if (token instanceof COSObject)
+            PDFStreamParser parser = new PDFStreamParser(is);
+            Object token = parser.parseNextToken();
+            while (token != null)
             {
-                arguments.add(((COSObject) token).getObject());
+                if (token instanceof COSObject)
+                {
+                    arguments.add(((COSObject) token).getObject());
+                }
+                else if (token instanceof Operator)
+                {
+                    processOperator((Operator) token, arguments);
+                    arguments = new ArrayList<>();
+                }
+                else
+                {
+                    arguments.add((COSBase) token);
+                }
+                token = parser.parseNextToken();
             }
-            else if (token instanceof Operator)
-            {
-                processOperator((Operator) token, arguments);
-                arguments = new ArrayList<>();
-            }
-            else
-            {
-                arguments.add((COSBase) token);
-            }
-            token = parser.parseNextToken();
         }
     }
 



Mime
View raw message