commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ggreg...@apache.org
Subject svn commit: r1747613 - in /commons/proper/imaging/trunk/src: main/java/org/apache/commons/imaging/formats/icns/IcnsImageParser.java test/java/org/apache/commons/imaging/formats/jpeg/iptc/IptcUpdateTest.java
Date Fri, 10 Jun 2016 00:24:16 GMT
Author: ggregory
Date: Fri Jun 10 00:24:16 2016
New Revision: 1747613

URL: http://svn.apache.org/viewvc?rev=1747613&view=rev
Log:
Use try-with-resources.

Modified:
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/icns/IcnsImageParser.java
    commons/proper/imaging/trunk/src/test/java/org/apache/commons/imaging/formats/jpeg/iptc/IptcUpdateTest.java

Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/icns/IcnsImageParser.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/icns/IcnsImageParser.java?rev=1747613&r1=1747612&r2=1747613&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/icns/IcnsImageParser.java
(original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/icns/IcnsImageParser.java
Fri Jun 10 00:24:16 2016
@@ -314,36 +314,36 @@ public class IcnsImageParser extends Ima
                     + src.getWidth() + " and height " + src.getHeight());
         }
 
-        final BinaryOutputStream bos = new BinaryOutputStream(os,
-                ByteOrder.BIG_ENDIAN);
-        bos.write4Bytes(ICNS_MAGIC);
-        bos.write4Bytes(4 + 4 + 4 + 4 + 4 * imageType.getWidth()
-                * imageType.getHeight() + 4 + 4 + imageType.getWidth()
-                * imageType.getHeight());
+        try (final BinaryOutputStream bos = new BinaryOutputStream(os,
+                ByteOrder.BIG_ENDIAN)) {
+            bos.write4Bytes(ICNS_MAGIC);
+            bos.write4Bytes(4 + 4 + 4 + 4 + 4 * imageType.getWidth()
+            * imageType.getHeight() + 4 + 4 + imageType.getWidth()
+            * imageType.getHeight());
 
-        bos.write4Bytes(imageType.getType());
-        bos.write4Bytes(4 + 4 + 4 * imageType.getWidth()
-                * imageType.getHeight());
-        for (int y = 0; y < src.getHeight(); y++) {
-            for (int x = 0; x < src.getWidth(); x++) {
-                final int argb = src.getRGB(x, y);
-                bos.write(0);
-                bos.write(argb >> 16);
-                bos.write(argb >> 8);
-                bos.write(argb);
+            bos.write4Bytes(imageType.getType());
+            bos.write4Bytes(4 + 4 + 4 * imageType.getWidth()
+            * imageType.getHeight());
+            for (int y = 0; y < src.getHeight(); y++) {
+                for (int x = 0; x < src.getWidth(); x++) {
+                    final int argb = src.getRGB(x, y);
+                    bos.write(0);
+                    bos.write(argb >> 16);
+                    bos.write(argb >> 8);
+                    bos.write(argb);
+                }
             }
-        }
 
-        final IcnsType maskType = IcnsType.find8BPPMaskType(imageType);
-        bos.write4Bytes(maskType.getType());
-        bos.write4Bytes(4 + 4 + imageType.getWidth() * imageType.getWidth());
-        for (int y = 0; y < src.getHeight(); y++) {
-            for (int x = 0; x < src.getWidth(); x++) {
-                final int argb = src.getRGB(x, y);
-                bos.write(argb >> 24);
+            final IcnsType maskType = IcnsType.find8BPPMaskType(imageType);
+            bos.write4Bytes(maskType.getType());
+            bos.write4Bytes(4 + 4 + imageType.getWidth() * imageType.getWidth());
+            for (int y = 0; y < src.getHeight(); y++) {
+                for (int x = 0; x < src.getWidth(); x++) {
+                    final int argb = src.getRGB(x, y);
+                    bos.write(argb >> 24);
+                }
             }
         }
-        bos.close();
     }
 
     /**

Modified: commons/proper/imaging/trunk/src/test/java/org/apache/commons/imaging/formats/jpeg/iptc/IptcUpdateTest.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/test/java/org/apache/commons/imaging/formats/jpeg/iptc/IptcUpdateTest.java?rev=1747613&r1=1747612&r2=1747613&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/test/java/org/apache/commons/imaging/formats/jpeg/iptc/IptcUpdateTest.java
(original)
+++ commons/proper/imaging/trunk/src/test/java/org/apache/commons/imaging/formats/jpeg/iptc/IptcUpdateTest.java
Fri Jun 10 00:24:16 2016
@@ -85,10 +85,9 @@ public class IptcUpdateTest extends Iptc
     public File removeIptc(ByteSource byteSource) throws Exception {
         final File noIptcFile = createTempFile(imageFile.getName() + ".iptc.remove.", ".jpg");
 
-        OutputStream os = new FileOutputStream(noIptcFile);
-        os = new BufferedOutputStream(os);
-        new JpegIptcRewriter().removeIPTC(byteSource, os);
-        os.close();
+        try (OutputStream os = new BufferedOutputStream(new FileOutputStream(noIptcFile)))
{
+            new JpegIptcRewriter().removeIPTC(byteSource, os);
+        }
         return noIptcFile;
     }
 



Mime
View raw message