pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1850410 - /pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/signature/ShowSignature.java
Date Fri, 04 Jan 2019 17:53:02 GMT
Author: tilman
Date: Fri Jan  4 17:53:02 2019
New Revision: 1850410

URL: http://svn.apache.org/viewvc?rev=1850410&view=rev
Log:
PDFBOX-4071: avoid memory leak

Modified:
    pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/signature/ShowSignature.java

Modified: pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/signature/ShowSignature.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/signature/ShowSignature.java?rev=1850410&r1=1850409&r2=1850410&view=diff
==============================================================================
--- pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/signature/ShowSignature.java
(original)
+++ pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/signature/ShowSignature.java
Fri Jan  4 17:53:02 2019
@@ -20,6 +20,7 @@ import java.io.ByteArrayInputStream;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.IOException;
+import java.io.InputStream;
 import java.security.GeneralSecurityException;
 import java.security.InvalidAlgorithmParameterException;
 import java.security.KeyStore;
@@ -607,12 +608,12 @@ public final class ShowSignature
             if (streamObj.getObject() instanceof COSStream)
             {
                 COSStream cosStream = (COSStream) streamObj.getObject();
-
-                COSInputStream input = cosStream.createInputStream();
-                byte[] streamBytes = IOUtils.toByteArray(input);
-
-                System.out.println(description + " (" + elements.indexOf(streamObj) + "):
"
+                try (InputStream is = cosStream.createInputStream())
+                {
+                    byte[] streamBytes = IOUtils.toByteArray(is);
+                    System.out.println(description + " (" + elements.indexOf(streamObj) +
"): "
                         + Hex.getString(streamBytes));
+                }
             }
         }
     }



Mime
View raw message