pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1792142 - in /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/image: CCITTFactory.java JPEGFactory.java LosslessFactory.java PDImageXObject.java
Date Thu, 20 Apr 2017 20:01:32 GMT
Author: tilman
Date: Thu Apr 20 20:01:32 2017
New Revision: 1792142

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

Modified:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/image/CCITTFactory.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/image/JPEGFactory.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/image/LosslessFactory.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/image/PDImageXObject.java

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/image/CCITTFactory.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/image/CCITTFactory.java?rev=1792142&r1=1792141&r2=1792142&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/image/CCITTFactory.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/image/CCITTFactory.java
Thu Apr 20 20:01:32 2017
@@ -69,22 +69,22 @@ public final class CCITTFactory
         int width = image.getWidth();
 
         ByteArrayOutputStream bos = new ByteArrayOutputStream();
-        MemoryCacheImageOutputStream mcios = new MemoryCacheImageOutputStream(bos);
-
-        for (int y = 0; y < height; ++y)
+        try (MemoryCacheImageOutputStream mcios = new MemoryCacheImageOutputStream(bos))
         {
-            for (int x = 0; x < width; ++x)
-            {
-                // flip bit to avoid having to set /BlackIs1
-                mcios.writeBits(~(image.getRGB(x, y) & 1), 1);
-            }
-            if (mcios.getBitOffset() != 0)
+            for (int y = 0; y < height; ++y)
             {
-                mcios.writeBits(0, 8 - mcios.getBitOffset());
+                for (int x = 0; x < width; ++x)
+                {
+                    // flip bit to avoid having to set /BlackIs1
+                    mcios.writeBits(~(image.getRGB(x, y) & 1), 1);
+                }
+                if (mcios.getBitOffset() != 0)
+                {
+                    mcios.writeBits(0, 8 - mcios.getBitOffset());
+                }
             }
+            mcios.flush();
         }
-        mcios.flush();
-        mcios.close();
 
         return prepareImageXObject(document, bos.toByteArray(), width, height, PDDeviceGray.INSTANCE);
     }

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/image/JPEGFactory.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/image/JPEGFactory.java?rev=1792142&r1=1792141&r2=1792142&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/image/JPEGFactory.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/image/JPEGFactory.java
Thu Apr 20 20:01:32 2017
@@ -128,21 +128,14 @@ public final class JPEGFactory
                     "a suitable JAI I/O image filter is not installed");
         }
 
-        ImageInputStream iis = null;
-        try
+        try (ImageInputStream iis = ImageIO.createImageInputStream(stream))
         {
-            iis = ImageIO.createImageInputStream(stream);
             reader.setInput(iis);
-
             ImageIO.setUseCache(false);
             return reader.read(0);
         }
         finally
         {
-            if (iis != null)
-            {
-                iis.close();
-            }
             reader.dispose();
         }
     }

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/image/LosslessFactory.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/image/LosslessFactory.java?rev=1792142&r1=1792141&r2=1792142&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/image/LosslessFactory.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/image/LosslessFactory.java
Thu Apr 20 20:01:32 2017
@@ -70,23 +70,23 @@ public final class LosslessFactory
             deviceColorSpace = PDDeviceGray.INSTANCE;
             
             ByteArrayOutputStream bos = new ByteArrayOutputStream((width*bpc/8)+(width*bpc%8
!= 0 ? 1:0)*height);
-            MemoryCacheImageOutputStream mcios = new MemoryCacheImageOutputStream(bos);
-            
-            for (int y = 0; y < height; ++y)
+            try (MemoryCacheImageOutputStream mcios = new MemoryCacheImageOutputStream(bos))
             {
-                for (int pixel : image.getRGB(0, y, width, 1, rgbLineBuffer, 0, width))
+                for (int y = 0; y < height; ++y)
                 {
-                    mcios.writeBits(pixel & 0xFF, bpc);
-                }
-                
-                int bitOffset = mcios.getBitOffset();
-                if (bitOffset != 0)
-                {
-                    mcios.writeBits(0, 8-bitOffset);
+                    for (int pixel : image.getRGB(0, y, width, 1, rgbLineBuffer, 0, width))
+                    {
+                        mcios.writeBits(pixel & 0xFF, bpc);
+                    }
+                    
+                    int bitOffset = mcios.getBitOffset();
+                    if (bitOffset != 0)
+                    {
+                        mcios.writeBits(0, 8-bitOffset);
+                    }
                 }
+                mcios.flush();
             }
-            mcios.flush();
-            mcios.close();
             
             imageData = bos.toByteArray();
         }
@@ -162,23 +162,24 @@ public final class LosslessFactory
         if (image.getTransparency() == Transparency.BITMASK)
         {
             bpc = 1;
-            MemoryCacheImageOutputStream mcios = new MemoryCacheImageOutputStream(bos);
-            int width = alphaRaster.getWidth();
-            int p = 0;
-            for (int pixel : pixels)
+            try (MemoryCacheImageOutputStream mcios = new MemoryCacheImageOutputStream(bos))
             {
-                mcios.writeBit(pixel);
-                ++p;
-                if (p % width == 0)
-                {
-                    while (mcios.getBitOffset() != 0)
+                int width = alphaRaster.getWidth();
+                int p = 0;
+                for (int pixel : pixels)
+                {
+                    mcios.writeBit(pixel);
+                    ++p;
+                    if (p % width == 0)
                     {
-                        mcios.writeBit(0);
+                        while (mcios.getBitOffset() != 0)
+                        {
+                            mcios.writeBit(0);
+                        }
                     }
                 }
+                mcios.flush();
             }
-            mcios.flush();
-            mcios.close();
         }
         else
         {
@@ -204,21 +205,22 @@ public final class LosslessFactory
         if (bi.getTransparency() == Transparency.BITMASK)
         {
             bpc = 1;
-            MemoryCacheImageOutputStream mcios = new MemoryCacheImageOutputStream(bos);
-            for (int y = 0, h = bi.getHeight(); y < h; ++y)
+            try (MemoryCacheImageOutputStream mcios = new MemoryCacheImageOutputStream(bos))
             {
-                for (int x = 0, w = bi.getWidth(); x < w; ++x)
+                for (int y = 0, h = bi.getHeight(); y < h; ++y)
                 {
-                    int alpha = bi.getRGB(x, y) >>> 24;
-                    mcios.writeBit(alpha);
-                }
-                while (mcios.getBitOffset() != 0)
-                {
-                    mcios.writeBit(0);
+                    for (int x = 0, w = bi.getWidth(); x < w; ++x)
+                    {
+                        int alpha = bi.getRGB(x, y) >>> 24;
+                        mcios.writeBit(alpha);
+                    }
+                    while (mcios.getBitOffset() != 0)
+                    {
+                        mcios.writeBit(0);
+                    }
                 }
+                mcios.flush();
             }
-            mcios.flush();
-            mcios.close();
         }
         else
         {

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/image/PDImageXObject.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/image/PDImageXObject.java?rev=1792142&r1=1792141&r2=1792142&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/image/PDImageXObject.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/image/PDImageXObject.java
Thu Apr 20 20:01:32 2017
@@ -269,10 +269,10 @@ public final class PDImageXObject extend
 
         if (fileType.equals(FileType.JPEG))
         {
-            FileInputStream fis = new FileInputStream(file);
-            PDImageXObject imageXObject = JPEGFactory.createFromStream(doc, fis);
-            fis.close();
-            return imageXObject;
+            try (FileInputStream fis = new FileInputStream(file))
+            {
+                return JPEGFactory.createFromStream(doc, fis);
+            }
         }
         if (fileType.equals(FileType.TIFF))
         {



Mime
View raw message