pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1798959 - in /pdfbox/trunk: examples/src/main/java/org/apache/pdfbox/examples/pdmodel/ pdfbox/src/main/java/org/apache/pdfbox/multipdf/ pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/ pdfbox/src/test/java/org/apache/pdfbox/multipdf/
Date Fri, 16 Jun 2017 16:29:41 GMT
Author: tilman
Date: Fri Jun 16 16:29:41 2017
New Revision: 1798959

URL: http://svn.apache.org/viewvc?rev=1798959&view=rev
Log:
PDFBOX-2852: use jdk7 syntax

Modified:
    pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/ImageToPDF.java
    pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/PrintURLs.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/multipdf/PDFMergerUtility.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/PDMetadata.java
    pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/multipdf/PDFMergerUtilityTest.java

Modified: pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/ImageToPDF.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/ImageToPDF.java?rev=1798959&r1=1798958&r2=1798959&view=diff
==============================================================================
--- pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/ImageToPDF.java
(original)
+++ pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/ImageToPDF.java
Fri Jun 16 16:29:41 2017
@@ -60,15 +60,15 @@ public final class ImageToPDF
             // call LosslessFactory.createFromImage() instead
             PDImageXObject pdImage = PDImageXObject.createFromFile(imagePath, doc);
             
-            PDPageContentStream contents = new PDPageContentStream(doc, page);
-            
             // draw the image at full size at (x=20, y=20)
-            contents.drawImage(pdImage, 20, 20);
-            
-            // to draw the image at half size at (x=20, y=20) use
-            // contents.drawImage(pdImage, 20, 20, pdImage.getWidth() / 2, pdImage.getHeight()
/ 2);
-            
-            contents.close();
+            try (PDPageContentStream contents = new PDPageContentStream(doc, page))
+            {
+                // draw the image at full size at (x=20, y=20)
+                contents.drawImage(pdImage, 20, 20);
+                
+                // to draw the image at half size at (x=20, y=20) use
+                // contents.drawImage(pdImage, 20, 20, pdImage.getWidth() / 2, pdImage.getHeight()
/ 2); 
+            }
             doc.save(pdfPath);
         }
     }

Modified: pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/PrintURLs.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/PrintURLs.java?rev=1798959&r1=1798958&r2=1798959&view=diff
==============================================================================
--- pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/PrintURLs.java
(original)
+++ pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/PrintURLs.java
Fri Jun 16 16:29:41 2017
@@ -147,13 +147,7 @@ public final class PrintURLs
                 }
             }
         }
-        catch (NoSuchMethodException e)
-        {
-        }
-        catch (IllegalAccessException e)
-        {
-        }
-        catch (InvocationTargetException e)
+        catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException
e)
         {
         }
         return null;

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/multipdf/PDFMergerUtility.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/multipdf/PDFMergerUtility.java?rev=1798959&r1=1798958&r2=1798959&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/multipdf/PDFMergerUtility.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/multipdf/PDFMergerUtility.java Fri
Jun 16 16:29:41 2017
@@ -494,7 +494,7 @@ public class PDFMergerUtility
         {
             PDStream newStream = new PDStream(destination, srcMetadata.createInputStream(),
(COSName) null);           
             mergeInto(srcMetadata, newStream.getCOSObject(), 
-                    new HashSet<COSName>(Arrays.asList(COSName.FILTER, COSName.LENGTH)));
          
+                    new HashSet<>(Arrays.asList(COSName.FILTER, COSName.LENGTH)));
          
             destCatalog.getCOSObject().setItem(COSName.METADATA, newStream);
         }
 

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/PDMetadata.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/PDMetadata.java?rev=1798959&r1=1798958&r2=1798959&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/PDMetadata.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/PDMetadata.java Fri
Jun 16 16:29:41 2017
@@ -94,8 +94,9 @@ public class PDMetadata extends PDStream
     public void importXMPMetadata( byte[] xmp )
         throws IOException
     {
-        OutputStream os = createOutputStream();
-        os.write(xmp);
-        os.close();
+        try (OutputStream os = createOutputStream())
+        {
+            os.write(xmp);
+        }
     }
 }

Modified: pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/multipdf/PDFMergerUtilityTest.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/multipdf/PDFMergerUtilityTest.java?rev=1798959&r1=1798958&r2=1798959&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/multipdf/PDFMergerUtilityTest.java
(original)
+++ pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/multipdf/PDFMergerUtilityTest.java
Fri Jun 16 16:29:41 2017
@@ -111,31 +111,36 @@ public class PDFMergerUtilityTest extend
                 MemoryUsageSetting.setupTempFileOnly());
     }
 
-    // checks that the result file of a merge has the same rendering as the two
-    // source files
+    // checks that the result file of a merge has the same rendering as the two source files
     private void checkMergeIdentical(String filename1, String filename2, String mergeFilename,

             MemoryUsageSetting memUsageSetting)
             throws IOException
     {
-        PDDocument srcDoc1 = PDDocument.load(new File(SRCDIR, filename1), (String)null);
-        int src1PageCount = srcDoc1.getNumberOfPages();
-        PDFRenderer src1PdfRenderer = new PDFRenderer(srcDoc1);
-        BufferedImage[] src1ImageTab = new BufferedImage[src1PageCount];
-        for (int page = 0; page < src1PageCount; ++page)
+        int src1PageCount;
+        BufferedImage[] src1ImageTab;
+        try (PDDocument srcDoc1 = PDDocument.load(new File(SRCDIR, filename1), (String) null))
         {
-            src1ImageTab[page] = src1PdfRenderer.renderImageWithDPI(page, DPI);
+            src1PageCount = srcDoc1.getNumberOfPages();
+            PDFRenderer src1PdfRenderer = new PDFRenderer(srcDoc1);
+            src1ImageTab = new BufferedImage[src1PageCount];
+            for (int page = 0; page < src1PageCount; ++page)
+            {
+                src1ImageTab[page] = src1PdfRenderer.renderImageWithDPI(page, DPI);
+            }
         }
-        srcDoc1.close();
 
-        PDDocument srcDoc2 = PDDocument.load(new File(SRCDIR, filename2), (String)null);
-        int src2PageCount = srcDoc2.getNumberOfPages();
-        PDFRenderer src2PdfRenderer = new PDFRenderer(srcDoc2);
-        BufferedImage[] src2ImageTab = new BufferedImage[src2PageCount];
-        for (int page = 0; page < src2PageCount; ++page)
+        int src2PageCount;
+        BufferedImage[] src2ImageTab;
+        try (PDDocument srcDoc2 = PDDocument.load(new File(SRCDIR, filename2), (String) null))
         {
-            src2ImageTab[page] = src2PdfRenderer.renderImageWithDPI(page, DPI);
+            src2PageCount = srcDoc2.getNumberOfPages();
+            PDFRenderer src2PdfRenderer = new PDFRenderer(srcDoc2);
+            src2ImageTab = new BufferedImage[src2PageCount];
+            for (int page = 0; page < src2PageCount; ++page)
+            {
+                src2ImageTab[page] = src2PdfRenderer.renderImageWithDPI(page, DPI);
+            }
         }
-        srcDoc2.close();
 
         PDFMergerUtility pdfMergerUtility = new PDFMergerUtility();
         pdfMergerUtility.addSource(new File(SRCDIR, filename1));
@@ -143,23 +148,23 @@ public class PDFMergerUtilityTest extend
         pdfMergerUtility.setDestinationFileName(TARGETTESTDIR + mergeFilename);
         pdfMergerUtility.mergeDocuments(memUsageSetting);
 
-        PDDocument mergedDoc
-                = PDDocument.load(new File(TARGETTESTDIR, mergeFilename), (String)null);
-        PDFRenderer mergePdfRenderer = new PDFRenderer(mergedDoc);
-        int mergePageCount = mergedDoc.getNumberOfPages();
-        assertEquals(src1PageCount + src2PageCount, mergePageCount);
-        for (int page = 0; page < src1PageCount; ++page)
+        try (PDDocument mergedDoc = PDDocument.load(new File(TARGETTESTDIR, mergeFilename),
(String) null))
         {
-            BufferedImage bim = mergePdfRenderer.renderImageWithDPI(page, DPI);
-            checkImagesIdentical(bim, src1ImageTab[page]);
+            PDFRenderer mergePdfRenderer = new PDFRenderer(mergedDoc);
+            int mergePageCount = mergedDoc.getNumberOfPages();
+            assertEquals(src1PageCount + src2PageCount, mergePageCount);
+            for (int page = 0; page < src1PageCount; ++page)
+            {
+                BufferedImage bim = mergePdfRenderer.renderImageWithDPI(page, DPI);
+                checkImagesIdentical(bim, src1ImageTab[page]);
+            }
+            for (int page = 0; page < src2PageCount; ++page)
+            {
+                int mergePage = page + src1PageCount;
+                BufferedImage bim = mergePdfRenderer.renderImageWithDPI(mergePage, DPI);
+                checkImagesIdentical(bim, src2ImageTab[page]);
+            }
         }
-        for (int page = 0; page < src2PageCount; ++page)
-        {
-            int mergePage = page + src1PageCount;
-            BufferedImage bim = mergePdfRenderer.renderImageWithDPI(mergePage, DPI);
-            checkImagesIdentical(bim, src2ImageTab[page]);
-        }
-        mergedDoc.close();
     }
 
     private void checkImagesIdentical(BufferedImage bim1, BufferedImage bim2)



Mime
View raw message