pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1817941 - /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfwriter/COSWriter.java
Date Tue, 12 Dec 2017 18:29:46 GMT
Author: tilman
Date: Tue Dec 12 18:29:46 2017
New Revision: 1817941

URL: http://svn.apache.org/viewvc?rev=1817941&view=rev
Log:
PDFBOX-2852: simplify code, reformat, change parameter name to be same as other constructor

Modified:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfwriter/COSWriter.java

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfwriter/COSWriter.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfwriter/COSWriter.java?rev=1817941&r1=1817940&r2=1817941&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfwriter/COSWriter.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfwriter/COSWriter.java Tue Dec 12
18:29:46 2017
@@ -223,11 +223,11 @@ public class COSWriter implements ICOSVi
     /**
      * COSWriter constructor comment.
      *
-     * @param os The wrapped output stream.
+     * @param outputStream The wrapped output stream.
      */
-    public COSWriter(OutputStream os)
+    public COSWriter(OutputStream outputStream)
     {
-        setOutput(os);
+        setOutput(outputStream);
         setStandardOutput(new COSStandardOutputStream(output));
     }
 
@@ -670,19 +670,17 @@ public class COSWriter implements ICOSVi
     }
 
     /**
-     * Write an incremental update for a non signature case. This can be used for e.g. augmenting
signatures.
-     * 
+     * Write an incremental update for a non signature case. This can be used for e.g. augmenting
+     * signatures.
+     *
      * @throws IOException
      */
     private void doWriteIncrement() throws IOException
     {
-        ByteArrayOutputStream byteOut = (ByteArrayOutputStream) output;
-        byteOut.flush();
-        byte[] buffer = byteOut.toByteArray();
-        SequenceInputStream signStream = new SequenceInputStream(new RandomAccessInputStream(incrementalInput),
-                                                                 new ByteArrayInputStream(buffer));
-        // write the data to the incremental output stream
-        IOUtils.copy(signStream, incrementalOutput);
+        // write existing PDF
+        IOUtils.copy(new RandomAccessInputStream(incrementalInput), incrementalOutput);
+        // write the actual incremental update
+        incrementalOutput.write(((ByteArrayOutputStream) output).toByteArray());
     }
     
     private void doWriteSignature() throws IOException
@@ -1130,14 +1128,16 @@ public class COSWriter implements ICOSVi
         getStandardOutput().write(EOF);
         getStandardOutput().writeEOL();
 
-        if(incrementalUpdate)
+        if (incrementalUpdate)
         {
-          if (signatureOffset == 0 || byteRangeOffset == 0)
-          {
-              doWriteIncrement();
-          } else {
-              doWriteSignature();
-          }
+            if (signatureOffset == 0 || byteRangeOffset == 0)
+            {
+                doWriteIncrement();
+            }
+            else
+            {
+                doWriteSignature();
+            }
         }
 
         return null;



Mime
View raw message