Author: tilman
Date: Tue Mar  6 17:42:46 2018
New Revision: 1826008

URL: http://svn.apache.org/viewvc?rev=1826008&view=rev
Log:
PDFBOX-4071: simplify code, close stream

Modified:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/multipdf/Overlay.java

Modified: 
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/multipdf/Overlay.java
URL: 
http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/multipdf/Overlay.java?rev=1826008&r1=1826007&r2=1826008&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/multipdf/Overlay.java 
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/multipdf/Overlay.java 
Tue Mar  6 17:42:46 2018
@@ -32,6 +32,7 @@ import org.apache.pdfbox.cos.COSDictiona
 import org.apache.pdfbox.cos.COSName;
 import org.apache.pdfbox.cos.COSObject;
 import org.apache.pdfbox.cos.COSStream;
+import org.apache.pdfbox.io.IOUtils;
 import org.apache.pdfbox.pdmodel.PDDocument;
 import org.apache.pdfbox.pdmodel.PDPage;
 import org.apache.pdfbox.pdmodel.PDResources;
@@ -291,14 +292,11 @@ public class Overlay
         {
             for (COSStream contentStream : contentStreams)
             {
-                InputStream in = contentStream.createInputStream();
-                byte[] buf = new byte[2048];
-                int n;
-                while ((n = in.read(buf)) > 0)
+                try (InputStream in = contentStream.createInputStream())
                 {
-                    out.write(buf, 0, n);
+                    IOUtils.copy(in, out);
+                    out.flush();
                 }
-                out.flush();
             }
         }
         return concatStream;


Reply via email to