Author: damjan
Date: Sat Sep  3 10:58:31 2016
New Revision: 1759073

URL: http://svn.apache.org/viewvc?rev=1759073&view=rev
Log:
Use try-with-resources everywhere.
Eliminate org.apache.commons.imaging.util.IoUtils.


Modified:
    
commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/bmp/BmpImageParser.java
    
commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/dcx/DcxImageParser.java
    
commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/gif/GifImageParser.java
    
commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/icns/IcnsImageParser.java
    
commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/ico/IcoImageParser.java
    
commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/JpegUtils.java
    
commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/exif/ExifRewriter.java
    
commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/iptc/IptcParser.java
    
commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/xmp/JpegRewriter.java
    
commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/pcx/PcxImageParser.java
    
commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/png/PngImageParser.java
    
commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/png/PngWriter.java
    
commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/pnm/PnmImageParser.java
    
commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/psd/PsdImageParser.java
    
commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/psd/datareaders/CompressedDataReader.java
    
commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/psd/datareaders/UncompressedDataReader.java
    
commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/rgbe/RgbeImageParser.java
    
commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/tiff/TiffReader.java
    
commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/wbmp/WbmpImageParser.java
    
commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/xbm/XbmImageParser.java
    
commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/xpm/XpmImageParser.java
    
commons/proper/imaging/trunk/src/test/java/org/apache/commons/imaging/formats/jpeg/iptc/IptcAddTest.java
    
commons/proper/imaging/trunk/src/test/java/org/apache/commons/imaging/formats/jpeg/iptc/IptcUpdateTest.java
    
commons/proper/imaging/trunk/src/test/java/org/apache/commons/imaging/formats/jpeg/xmp/JpegXmpRewriteTest.java

Modified: 
commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/bmp/BmpImageParser.java
URL: 
http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/bmp/BmpImageParser.java?rev=1759073&r1=1759072&r2=1759073&view=diff
==============================================================================
--- 
commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/bmp/BmpImageParser.java
 (original)
+++ 
commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/bmp/BmpImageParser.java
 Sat Sep  3 10:58:31 2016
@@ -16,6 +16,15 @@
  */
 package org.apache.commons.imaging.formats.bmp;
 
+import static 
org.apache.commons.imaging.ImagingConstants.BUFFERED_IMAGE_FACTORY;
+import static org.apache.commons.imaging.ImagingConstants.PARAM_KEY_FORMAT;
+import static 
org.apache.commons.imaging.ImagingConstants.PARAM_KEY_PIXEL_DENSITY;
+import static org.apache.commons.imaging.ImagingConstants.PARAM_KEY_VERBOSE;
+import static org.apache.commons.imaging.common.BinaryFunctions.read2Bytes;
+import static org.apache.commons.imaging.common.BinaryFunctions.read4Bytes;
+import static org.apache.commons.imaging.common.BinaryFunctions.readByte;
+import static org.apache.commons.imaging.common.BinaryFunctions.readBytes;
+
 import java.awt.Dimension;
 import java.awt.image.BufferedImage;
 import java.io.ByteArrayOutputStream;
@@ -38,15 +47,11 @@ import org.apache.commons.imaging.ImageR
 import org.apache.commons.imaging.ImageWriteException;
 import org.apache.commons.imaging.PixelDensity;
 import org.apache.commons.imaging.common.BinaryOutputStream;
-import org.apache.commons.imaging.common.ImageMetadata;
 import org.apache.commons.imaging.common.ImageBuilder;
+import org.apache.commons.imaging.common.ImageMetadata;
 import org.apache.commons.imaging.common.bytesource.ByteSource;
 import org.apache.commons.imaging.palette.PaletteFactory;
 import org.apache.commons.imaging.palette.SimplePalette;
-import org.apache.commons.imaging.util.IoUtils;
-
-import static org.apache.commons.imaging.ImagingConstants.*;
-import static org.apache.commons.imaging.common.BinaryFunctions.*;
 
 public class BmpImageParser extends ImageParser {
     private static final String DEFAULT_EXTENSION = ".bmp";
@@ -471,17 +476,10 @@ public class BmpImageParser extends Imag
 
     private BmpHeaderInfo readBmpHeaderInfo(final ByteSource byteSource,
             final boolean verbose) throws ImageReadException, IOException {
-        InputStream is = null;
-        boolean canThrow = false;
-        try {
-            is = byteSource.getInputStream();
-
+        try (InputStream is = byteSource.getInputStream()) {
             // readSignature(is);
             final BmpHeaderInfo ret = readBmpHeaderInfo(is, null, verbose);
-            canThrow = true;
             return ret;
-        } finally {
-            IoUtils.closeQuietly(canThrow, is);
         }
     }
 
@@ -565,15 +563,9 @@ public class BmpImageParser extends Imag
             throw new ImageReadException("Unknown parameter: " + firstKey);
         }
 
-        InputStream is = null;
         ImageContents ic = null;
-        boolean canThrow = false;
-        try {
-            is = byteSource.getInputStream();
+        try (InputStream is = byteSource.getInputStream()) {
             ic = readImageContents(is, FormatCompliance.getDefault(), verbose);
-            canThrow = true;
-        } finally {
-            IoUtils.closeQuietly(canThrow, is);
         }
 
         if (ic == null) {
@@ -649,14 +641,8 @@ public class BmpImageParser extends Imag
         final FormatCompliance result = new FormatCompliance(
                 byteSource.getDescription());
 
-        InputStream is = null;
-        boolean canThrow = false;
-        try {
-            is = byteSource.getInputStream();
+        try (InputStream is = byteSource.getInputStream()) {
             readImageContents(is, result, verbose);
-            canThrow = true;
-        } finally {
-            IoUtils.closeQuietly(canThrow, is);
         }
 
         return result;
@@ -665,15 +651,9 @@ public class BmpImageParser extends Imag
     @Override
     public BufferedImage getBufferedImage(final ByteSource byteSource, final 
Map<String, Object> params)
             throws ImageReadException, IOException {
-        InputStream is = null;
-        boolean canThrow = false;
-        try {
-            is = byteSource.getInputStream();
+        try (InputStream is = byteSource.getInputStream()) {
             final BufferedImage ret = getBufferedImage(is, params);
-            canThrow = true;
             return ret;
-        } finally {
-            IoUtils.closeQuietly(canThrow, is);
         }
     }
 

Modified: 
commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/dcx/DcxImageParser.java
URL: 
http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/dcx/DcxImageParser.java?rev=1759073&r1=1759072&r2=1759073&view=diff
==============================================================================
--- 
commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/dcx/DcxImageParser.java
 (original)
+++ 
commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/dcx/DcxImageParser.java
 Sat Sep  3 10:58:31 2016
@@ -16,6 +16,10 @@
  */
 package org.apache.commons.imaging.formats.dcx;
 
+import static org.apache.commons.imaging.ImagingConstants.PARAM_KEY_FORMAT;
+import static 
org.apache.commons.imaging.ImagingConstants.PARAM_KEY_PIXEL_DENSITY;
+import static org.apache.commons.imaging.common.BinaryFunctions.read4Bytes;
+
 import java.awt.Dimension;
 import java.awt.image.BufferedImage;
 import java.io.IOException;
@@ -41,10 +45,6 @@ import org.apache.commons.imaging.common
 import org.apache.commons.imaging.common.bytesource.ByteSourceInputStream;
 import org.apache.commons.imaging.formats.pcx.PcxConstants;
 import org.apache.commons.imaging.formats.pcx.PcxImageParser;
-import org.apache.commons.imaging.util.IoUtils;
-
-import static org.apache.commons.imaging.ImagingConstants.*;
-import static org.apache.commons.imaging.common.BinaryFunctions.*;
 
 public class DcxImageParser extends ImageParser {
     // See http://www.fileformat.info/format/pcx/egff.htm for documentation
@@ -126,10 +126,7 @@ public class DcxImageParser extends Imag
 
     private DcxHeader readDcxHeader(final ByteSource byteSource)
             throws ImageReadException, IOException {
-        InputStream is = null;
-        boolean canThrow = false;
-        try {
-            is = byteSource.getInputStream();
+        try (InputStream is = byteSource.getInputStream()) {
             final int id = read4Bytes("Id", is, "Not a Valid DCX File", 
getByteOrder());
             final List<Long> pageTable = new ArrayList<>(1024);
             for (int i = 0; i < 1024; i++) {
@@ -157,10 +154,7 @@ public class DcxImageParser extends Imag
             }
 
             final DcxHeader ret = new DcxHeader(id, pages);
-            canThrow = true;
             return ret;
-        } finally {
-            IoUtils.closeQuietly(canThrow, is);
         }
     }
 
@@ -188,18 +182,12 @@ public class DcxImageParser extends Imag
         final List<BufferedImage> images = new ArrayList<>();
         final PcxImageParser pcxImageParser = new PcxImageParser();
         for (final long element : dcxHeader.pageTable) {
-            InputStream stream = null;
-            boolean canThrow = false;
-            try {
-                stream = byteSource.getInputStream(element);
+            try (InputStream stream = byteSource.getInputStream(element)) {
                 final ByteSourceInputStream pcxSource = new 
ByteSourceInputStream(
                         stream, null);
                 final BufferedImage image = pcxImageParser.getBufferedImage(
                         pcxSource, new HashMap<String, Object>());
                 images.add(image);
-                canThrow = true;
-            } finally {
-                IoUtils.closeQuietly(canThrow, stream);
             }
         }
         return images;

Modified: 
commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/gif/GifImageParser.java
URL: 
http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/gif/GifImageParser.java?rev=1759073&r1=1759072&r2=1759073&view=diff
==============================================================================
--- 
commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/gif/GifImageParser.java
 (original)
+++ 
commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/gif/GifImageParser.java
 Sat Sep  3 10:58:31 2016
@@ -16,6 +16,16 @@
  */
 package org.apache.commons.imaging.formats.gif;
 
+import static org.apache.commons.imaging.ImagingConstants.PARAM_KEY_FORMAT;
+import static org.apache.commons.imaging.ImagingConstants.PARAM_KEY_VERBOSE;
+import static org.apache.commons.imaging.ImagingConstants.PARAM_KEY_XMP_XML;
+import static org.apache.commons.imaging.common.BinaryFunctions.compareBytes;
+import static org.apache.commons.imaging.common.BinaryFunctions.printByteBits;
+import static org.apache.commons.imaging.common.BinaryFunctions.printCharQuad;
+import static org.apache.commons.imaging.common.BinaryFunctions.read2Bytes;
+import static org.apache.commons.imaging.common.BinaryFunctions.readByte;
+import static org.apache.commons.imaging.common.BinaryFunctions.readBytes;
+
 import java.awt.Dimension;
 import java.awt.image.BufferedImage;
 import java.io.ByteArrayInputStream;
@@ -38,17 +48,13 @@ import org.apache.commons.imaging.ImageP
 import org.apache.commons.imaging.ImageReadException;
 import org.apache.commons.imaging.ImageWriteException;
 import org.apache.commons.imaging.common.BinaryOutputStream;
-import org.apache.commons.imaging.common.ImageMetadata;
 import org.apache.commons.imaging.common.ImageBuilder;
+import org.apache.commons.imaging.common.ImageMetadata;
 import org.apache.commons.imaging.common.bytesource.ByteSource;
 import org.apache.commons.imaging.common.mylzw.MyLzwCompressor;
 import org.apache.commons.imaging.common.mylzw.MyLzwDecompressor;
 import org.apache.commons.imaging.palette.Palette;
 import org.apache.commons.imaging.palette.PaletteFactory;
-import org.apache.commons.imaging.util.IoUtils;
-
-import static org.apache.commons.imaging.ImagingConstants.*;
-import static org.apache.commons.imaging.common.BinaryFunctions.*;
 
 public class GifImageParser extends ImageParser {
     private static final String DEFAULT_EXTENSION = ".gif";
@@ -439,11 +445,7 @@ public class GifImageParser extends Imag
     private ImageContents readFile(final ByteSource byteSource,
             final boolean stopBeforeImageData, final FormatCompliance 
formatCompliance)
             throws ImageReadException, IOException {
-        InputStream is = null;
-        boolean canThrow = false;
-        try {
-            is = byteSource.getInputStream();
-
+        try (InputStream is = byteSource.getInputStream()) {
             final GifHeaderInfo ghi = readHeader(is, formatCompliance);
 
             byte[] globalColorTable = null;
@@ -457,10 +459,7 @@ public class GifImageParser extends Imag
 
             final ImageContents result = new ImageContents(ghi, 
globalColorTable,
                     blocks);
-            canThrow = true;
             return result;
-        } finally {
-            IoUtils.closeQuietly(canThrow, is);
         }
     }
 
@@ -1005,12 +1004,7 @@ public class GifImageParser extends Imag
     @Override
     public String getXmpXml(final ByteSource byteSource, final Map<String, 
Object> params)
             throws ImageReadException, IOException {
-
-        InputStream is = null;
-        boolean canThrow = false;
-        try {
-            is = byteSource.getInputStream();
-
+        try (InputStream is = byteSource.getInputStream()) {
             final FormatCompliance formatCompliance = null;
             final GifHeaderInfo ghi = readHeader(is, formatCompliance);
 
@@ -1075,11 +1069,7 @@ public class GifImageParser extends Imag
             if (result.size() > 1) {
                 throw new ImageReadException("More than one XMP Block in 
GIF.");
             }
-            canThrow = true;
             return result.get(0);
-
-        } finally {
-            IoUtils.closeQuietly(canThrow, is);
         }
     }
 }

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=1759073&r1=1759072&r2=1759073&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
 Sat Sep  3 10:58:31 2016
@@ -16,6 +16,11 @@
  */
 package org.apache.commons.imaging.formats.icns;
 
+import static org.apache.commons.imaging.ImagingConstants.PARAM_KEY_FORMAT;
+import static org.apache.commons.imaging.ImagingConstants.PARAM_KEY_VERBOSE;
+import static org.apache.commons.imaging.common.BinaryFunctions.read4Bytes;
+import static org.apache.commons.imaging.common.BinaryFunctions.readBytes;
+
 import java.awt.Dimension;
 import java.awt.image.BufferedImage;
 import java.io.IOException;
@@ -37,10 +42,6 @@ import org.apache.commons.imaging.ImageW
 import org.apache.commons.imaging.common.BinaryOutputStream;
 import org.apache.commons.imaging.common.ImageMetadata;
 import org.apache.commons.imaging.common.bytesource.ByteSource;
-import org.apache.commons.imaging.util.IoUtils;
-
-import static org.apache.commons.imaging.ImagingConstants.*;
-import static org.apache.commons.imaging.common.BinaryFunctions.*;
 
 public class IcnsImageParser extends ImageParser {
     static final int ICNS_MAGIC = IcnsType.typeAsInt("icns");
@@ -228,10 +229,7 @@ public class IcnsImageParser extends Ima
 
     private IcnsContents readImage(final ByteSource byteSource)
             throws ImageReadException, IOException {
-        InputStream is = null;
-        boolean canThrow = false;
-        try {
-            is = byteSource.getInputStream();
+        try (InputStream is = byteSource.getInputStream()) {
             final IcnsHeader icnsHeader = readIcnsHeader(is);
 
             final List<IcnsElement> icnsElementList = new ArrayList<>();
@@ -247,10 +245,7 @@ public class IcnsImageParser extends Ima
             }
 
             final IcnsContents ret = new IcnsContents(icnsHeader, 
icnsElements);
-            canThrow = true;
             return ret;
-        } finally {
-            IoUtils.closeQuietly(canThrow, is);
         }
     }
 

Modified: 
commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/ico/IcoImageParser.java
URL: 
http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/ico/IcoImageParser.java?rev=1759073&r1=1759072&r2=1759073&view=diff
==============================================================================
--- 
commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/ico/IcoImageParser.java
 (original)
+++ 
commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/ico/IcoImageParser.java
 Sat Sep  3 10:58:31 2016
@@ -16,6 +16,13 @@
  */
 package org.apache.commons.imaging.formats.ico;
 
+import static org.apache.commons.imaging.ImagingConstants.PARAM_KEY_FORMAT;
+import static 
org.apache.commons.imaging.ImagingConstants.PARAM_KEY_PIXEL_DENSITY;
+import static org.apache.commons.imaging.common.BinaryFunctions.read2Bytes;
+import static org.apache.commons.imaging.common.BinaryFunctions.read4Bytes;
+import static org.apache.commons.imaging.common.BinaryFunctions.readByte;
+import static org.apache.commons.imaging.common.BinaryFunctions.readBytes;
+
 import java.awt.Dimension;
 import java.awt.image.BufferedImage;
 import java.io.ByteArrayInputStream;
@@ -44,10 +51,6 @@ import org.apache.commons.imaging.common
 import org.apache.commons.imaging.formats.bmp.BmpImageParser;
 import org.apache.commons.imaging.palette.PaletteFactory;
 import org.apache.commons.imaging.palette.SimplePalette;
-import org.apache.commons.imaging.util.IoUtils;
-
-import static org.apache.commons.imaging.ImagingConstants.*;
-import static org.apache.commons.imaging.common.BinaryFunctions.*;
 
 public class IcoImageParser extends ImageParser {
     private static final String DEFAULT_EXTENSION = ".ico";
@@ -428,12 +431,7 @@ public class IcoImageParser extends Imag
         final int bitmapSize = 14 + 56 + restOfFile.length;
 
         final ByteArrayOutputStream baos = new 
ByteArrayOutputStream(bitmapSize);
-        BinaryOutputStream bos = null;
-        boolean canThrow = false;
-        try {
-            bos = new BinaryOutputStream(baos,
-                    ByteOrder.LITTLE_ENDIAN);
-    
+        try (BinaryOutputStream bos = new BinaryOutputStream(baos, 
ByteOrder.LITTLE_ENDIAN)) {
             bos.write('B');
             bos.write('M');
             bos.write4Bytes(bitmapSize);
@@ -457,9 +455,6 @@ public class IcoImageParser extends Imag
             bos.write4Bytes(alphaMask);
             bos.write(restOfFile);
             bos.flush();
-            canThrow = true;
-        } finally {
-            IoUtils.closeQuietly(canThrow, bos);
         }
 
         final ByteArrayInputStream bmpInputStream = new 
ByteArrayInputStream(baos.toByteArray());
@@ -547,10 +542,7 @@ public class IcoImageParser extends Imag
 
     private ImageContents readImage(final ByteSource byteSource)
             throws ImageReadException, IOException {
-        InputStream is = null;
-        boolean canThrow = false;
-        try {
-            is = byteSource.getInputStream();
+        try (InputStream is = byteSource.getInputStream()) {
             final FileHeader fileHeader = readFileHeader(is);
 
             final IconInfo[] fIconInfos = new IconInfo[fileHeader.iconCount];
@@ -566,10 +558,7 @@ public class IcoImageParser extends Imag
             }
 
             final ImageContents ret = new ImageContents(fileHeader, 
fIconDatas);
-            canThrow = true;
             return ret;
-        } finally {
-            IoUtils.closeQuietly(canThrow, is);
         }
     }
 

Modified: 
commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/JpegUtils.java
URL: 
http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/JpegUtils.java?rev=1759073&r1=1759072&r2=1759073&view=diff
==============================================================================
--- 
commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/JpegUtils.java
 (original)
+++ 
commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/JpegUtils.java
 Sat Sep  3 10:58:31 2016
@@ -16,6 +16,11 @@
  */
 package org.apache.commons.imaging.formats.jpeg;
 
+import static org.apache.commons.imaging.common.BinaryFunctions.getStreamBytes;
+import static 
org.apache.commons.imaging.common.BinaryFunctions.readAndVerifyBytes;
+import static org.apache.commons.imaging.common.BinaryFunctions.readByte;
+import static org.apache.commons.imaging.common.BinaryFunctions.readBytes;
+
 import java.io.IOException;
 import java.io.InputStream;
 import java.nio.ByteOrder;
@@ -25,9 +30,6 @@ import org.apache.commons.imaging.common
 import org.apache.commons.imaging.common.ByteConversions;
 import org.apache.commons.imaging.common.bytesource.ByteSource;
 import org.apache.commons.imaging.util.Debug;
-import org.apache.commons.imaging.util.IoUtils;
-
-import static org.apache.commons.imaging.common.BinaryFunctions.*;
 
 public class JpegUtils extends BinaryFileParser {
     public JpegUtils() {
@@ -50,11 +52,7 @@ public class JpegUtils extends BinaryFil
     public void traverseJFIF(final ByteSource byteSource, final Visitor 
visitor)
             throws ImageReadException,
             IOException {
-        InputStream is = null;
-        boolean canThrow = false;
-        try {
-            is = byteSource.getInputStream();
-
+        try (InputStream is = byteSource.getInputStream()) {
             readAndVerifyBytes(is, JpegConstants.SOI,
                     "Not a Valid JPEG File: doesn't begin with 0xffd8");
 
@@ -72,7 +70,6 @@ public class JpegUtils extends BinaryFil
 
                 if (marker == JpegConstants.EOI_MARKER || marker == 
JpegConstants.SOS_MARKER) {
                     if (!visitor.beginSOS()) {
-                        canThrow = true;
                         return;
                     }
 
@@ -89,15 +86,11 @@ public class JpegUtils extends BinaryFil
                         "Invalid Segment: insufficient data");
 
                 if (!visitor.visitSegment(marker, markerBytes, segmentLength, 
segmentLengthBytes, segmentData)) {
-                    canThrow = true;
                     return;
                 }
             }
             
             Debug.debug(Integer.toString(markerCount) + " markers");
-            canThrow = true;
-        } finally {
-            IoUtils.closeQuietly(canThrow, is);
         }
     }
 

Modified: 
commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/exif/ExifRewriter.java
URL: 
http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/exif/ExifRewriter.java?rev=1759073&r1=1759072&r2=1759073&view=diff
==============================================================================
--- 
commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/exif/ExifRewriter.java
 (original)
+++ 
commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/exif/ExifRewriter.java
 Sat Sep  3 10:58:31 2016
@@ -16,7 +16,11 @@
  */
 package org.apache.commons.imaging.formats.jpeg.exif;
 
+import static org.apache.commons.imaging.common.BinaryFunctions.remainingBytes;
+import static org.apache.commons.imaging.common.BinaryFunctions.startsWith;
+
 import java.io.ByteArrayOutputStream;
+import java.io.DataOutputStream;
 import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
@@ -39,9 +43,6 @@ import org.apache.commons.imaging.format
 import org.apache.commons.imaging.formats.tiff.write.TiffImageWriterLossless;
 import org.apache.commons.imaging.formats.tiff.write.TiffImageWriterLossy;
 import org.apache.commons.imaging.formats.tiff.write.TiffOutputSet;
-import org.apache.commons.imaging.util.IoUtils;
-
-import static org.apache.commons.imaging.common.BinaryFunctions.*;
 
 /**
  * Interface for Exif write/update/remove functionality for Jpeg/JFIF images.
@@ -497,12 +498,11 @@ public class ExifRewriter extends Binary
         writeSegmentsReplacingExif(os, pieces, newBytes);
     }
 
-    private void writeSegmentsReplacingExif(final OutputStream os,
+    private void writeSegmentsReplacingExif(final OutputStream outputStream,
             final List<JFIFPiece> segments, final byte[] newBytes)
             throws ImageWriteException, IOException {
 
-        boolean canThrow = false;
-        try {
+        try (DataOutputStream os = new DataOutputStream(outputStream)) {
             JpegConstants.SOI.writeTo(os);
 
             boolean hasExif = false;
@@ -561,9 +561,6 @@ public class ExifRewriter extends Binary
                     piece.write(os);
                 }
             }
-            canThrow = true;
-        } finally {
-            IoUtils.closeQuietly(canThrow, os);
         }
     }
 

Modified: 
commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/iptc/IptcParser.java
URL: 
http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/iptc/IptcParser.java?rev=1759073&r1=1759072&r2=1759073&view=diff
==============================================================================
--- 
commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/iptc/IptcParser.java
 (original)
+++ 
commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/iptc/IptcParser.java
 Sat Sep  3 10:58:31 2016
@@ -17,6 +17,13 @@
 
 package org.apache.commons.imaging.formats.jpeg.iptc;
 
+import static org.apache.commons.imaging.common.BinaryFunctions.read2Bytes;
+import static org.apache.commons.imaging.common.BinaryFunctions.read4Bytes;
+import static org.apache.commons.imaging.common.BinaryFunctions.readByte;
+import static org.apache.commons.imaging.common.BinaryFunctions.readBytes;
+import static org.apache.commons.imaging.common.BinaryFunctions.slice;
+import static org.apache.commons.imaging.common.BinaryFunctions.startsWith;
+
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
@@ -36,9 +43,6 @@ import org.apache.commons.imaging.common
 import org.apache.commons.imaging.common.ByteConversions;
 import org.apache.commons.imaging.formats.jpeg.JpegConstants;
 import org.apache.commons.imaging.util.Debug;
-import org.apache.commons.imaging.util.IoUtils;
-
-import static org.apache.commons.imaging.common.BinaryFunctions.*;
 
 public class IptcParser extends BinaryFileParser {
     private static final ByteOrder APP13_BYTE_ORDER = ByteOrder.BIG_ENDIAN;
@@ -252,10 +256,7 @@ public class IptcParser extends BinaryFi
             final boolean strict) throws ImageReadException, IOException {
         final List<IptcBlock> blocks = new ArrayList<>();
 
-        InputStream bis = null;
-        boolean canThrow = false;
-        try {
-            bis = new ByteArrayInputStream(bytes);
+        try (InputStream bis = new ByteArrayInputStream(bytes)) {
 
             // Note that these are unsigned quantities. Name is always an even
             // number of bytes (including the 1st byte, which is the size.)
@@ -342,10 +343,7 @@ public class IptcParser extends BinaryFi
                 }
             }
     
-            canThrow = true;
             return blocks;
-        } finally {
-            IoUtils.closeQuietly(canThrow, bis);
         }
     }
 
@@ -397,11 +395,7 @@ public class IptcParser extends BinaryFi
             throws ImageWriteException, IOException {
         byte[] blockData;
         final ByteArrayOutputStream baos = new ByteArrayOutputStream();
-        BinaryOutputStream bos = null;
-        boolean canThrow = false;
-        try {
-            bos = new BinaryOutputStream(baos,
-                    getByteOrder());
+        try (BinaryOutputStream bos = new BinaryOutputStream(baos, 
getByteOrder())) {
     
             // first, right record version record
             bos.write(IptcConstants.IPTC_RECORD_TAG_MARKER);
@@ -448,9 +442,6 @@ public class IptcParser extends BinaryFi
                 bos.write2Bytes(recordData.length);
                 bos.write(recordData);
             }
-            canThrow = true;
-        } finally {
-            IoUtils.closeQuietly(canThrow, bos);
         }
 
         blockData = baos.toByteArray();

Modified: 
commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/xmp/JpegRewriter.java
URL: 
http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/xmp/JpegRewriter.java?rev=1759073&r1=1759072&r2=1759073&view=diff
==============================================================================
--- 
commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/xmp/JpegRewriter.java
 (original)
+++ 
commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/xmp/JpegRewriter.java
 Sat Sep  3 10:58:31 2016
@@ -16,6 +16,9 @@
  */
 package org.apache.commons.imaging.formats.jpeg.xmp;
 
+import static org.apache.commons.imaging.common.BinaryFunctions.startsWith;
+
+import java.io.DataOutputStream;
 import java.io.IOException;
 import java.io.OutputStream;
 import java.nio.ByteOrder;
@@ -30,9 +33,6 @@ import org.apache.commons.imaging.common
 import org.apache.commons.imaging.formats.jpeg.JpegConstants;
 import org.apache.commons.imaging.formats.jpeg.JpegUtils;
 import org.apache.commons.imaging.formats.jpeg.iptc.IptcParser;
-import org.apache.commons.imaging.util.IoUtils;
-
-import static org.apache.commons.imaging.common.BinaryFunctions.*;
 
 /**
  * Interface for Exif write/update/remove functionality for Jpeg/JFIF images.
@@ -313,18 +313,14 @@ public class JpegRewriter extends Binary
         return result;
     }
 
-    protected void writeSegments(final OutputStream os,
+    protected void writeSegments(final OutputStream outputStream,
             final List<? extends JFIFPiece> segments) throws IOException {
-        boolean canThrow = false;
-        try {
+        try (DataOutputStream os = new DataOutputStream(outputStream)) {
             JpegConstants.SOI.writeTo(os);
 
             for (JFIFPiece piece : segments) {
                 piece.write(os);
             }
-            canThrow = true;
-        } finally {
-            IoUtils.closeQuietly(canThrow, os);
         }
     }
 

Modified: 
commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/pcx/PcxImageParser.java
URL: 
http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/pcx/PcxImageParser.java?rev=1759073&r1=1759072&r2=1759073&view=diff
==============================================================================
--- 
commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/pcx/PcxImageParser.java
 (original)
+++ 
commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/pcx/PcxImageParser.java
 Sat Sep  3 10:58:31 2016
@@ -16,6 +16,12 @@
  */
 package org.apache.commons.imaging.formats.pcx;
 
+import static org.apache.commons.imaging.ImagingConstants.PARAM_KEY_STRICT;
+import static org.apache.commons.imaging.common.BinaryFunctions.readByte;
+import static org.apache.commons.imaging.common.BinaryFunctions.readBytes;
+import static org.apache.commons.imaging.common.BinaryFunctions.skipBytes;
+import static org.apache.commons.imaging.common.ByteConversions.toUInt16;
+
 import java.awt.Dimension;
 import java.awt.Transparency;
 import java.awt.color.ColorSpace;
@@ -46,11 +52,6 @@ import org.apache.commons.imaging.ImageR
 import org.apache.commons.imaging.ImageWriteException;
 import org.apache.commons.imaging.common.ImageMetadata;
 import org.apache.commons.imaging.common.bytesource.ByteSource;
-import org.apache.commons.imaging.util.IoUtils;
-
-import static org.apache.commons.imaging.ImagingConstants.*;
-import static org.apache.commons.imaging.common.BinaryFunctions.*;
-import static org.apache.commons.imaging.common.ByteConversions.*;
 
 public class PcxImageParser extends ImageParser {
     // ZSoft's official spec is at http://www.qzx.com/pc-gpe/pcx.txt
@@ -240,15 +241,9 @@ public class PcxImageParser extends Imag
 
     private PcxHeader readPcxHeader(final ByteSource byteSource)
             throws ImageReadException, IOException {
-        InputStream is = null;
-        boolean canThrow = false;
-        try {
-            is = byteSource.getInputStream();
+        try (InputStream is = byteSource.getInputStream()) {
             final PcxHeader ret = readPcxHeader(is, false);
-            canThrow = true;
             return ret;
-        } finally {
-            IoUtils.closeQuietly(canThrow, is);
         }
     }
 
@@ -359,17 +354,11 @@ public class PcxImageParser extends Imag
 
     private int[] read256ColorPaletteFromEndOfFile(final ByteSource byteSource)
             throws IOException {
-        InputStream stream = null;
-        boolean canThrow = false;
-        try {
-            stream = byteSource.getInputStream();
+        try (InputStream stream = byteSource.getInputStream()) {
             final long toSkip = byteSource.getLength() - 769;
             skipBytes(stream, (int) toSkip);
             final int[] ret = read256ColorPalette(stream);
-            canThrow = true;
             return ret;
-        } finally {
-            IoUtils.closeQuietly(canThrow, stream);
         }
     }
 
@@ -522,16 +511,10 @@ public class PcxImageParser extends Imag
             isStrict = ((Boolean) strictness).booleanValue();
         }
 
-        InputStream is = null;
-        boolean canThrow = false;
-        try {
-            is = byteSource.getInputStream();
+        try (InputStream is = byteSource.getInputStream()) {
             final PcxHeader pcxHeader = readPcxHeader(is, isStrict);
             final BufferedImage ret = readImage(pcxHeader, is, byteSource);
-            canThrow = true;
             return ret;
-        } finally {
-            IoUtils.closeQuietly(canThrow, is);
         }
     }
 

Modified: 
commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/png/PngImageParser.java
URL: 
http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/png/PngImageParser.java?rev=1759073&r1=1759072&r2=1759073&view=diff
==============================================================================
--- 
commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/png/PngImageParser.java
 (original)
+++ 
commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/png/PngImageParser.java
 Sat Sep  3 10:58:31 2016
@@ -16,6 +16,13 @@
  */
 package org.apache.commons.imaging.formats.png;
 
+import static org.apache.commons.imaging.ImagingConstants.PARAM_KEY_VERBOSE;
+import static org.apache.commons.imaging.common.BinaryFunctions.printCharQuad;
+import static org.apache.commons.imaging.common.BinaryFunctions.read4Bytes;
+import static 
org.apache.commons.imaging.common.BinaryFunctions.readAndVerifyBytes;
+import static org.apache.commons.imaging.common.BinaryFunctions.readBytes;
+import static org.apache.commons.imaging.common.BinaryFunctions.skipBytes;
+
 import java.awt.Dimension;
 import java.awt.color.ColorSpace;
 import java.awt.color.ICC_ColorSpace;
@@ -41,8 +48,8 @@ import org.apache.commons.imaging.ImageI
 import org.apache.commons.imaging.ImageParser;
 import org.apache.commons.imaging.ImageReadException;
 import org.apache.commons.imaging.ImageWriteException;
-import org.apache.commons.imaging.common.ImageMetadata;
 import org.apache.commons.imaging.common.GenericImageMetadata;
+import org.apache.commons.imaging.common.ImageMetadata;
 import org.apache.commons.imaging.common.bytesource.ByteSource;
 import org.apache.commons.imaging.formats.png.chunks.PngChunk;
 import org.apache.commons.imaging.formats.png.chunks.PngChunkGama;
@@ -61,10 +68,6 @@ import org.apache.commons.imaging.format
 import 
org.apache.commons.imaging.formats.png.transparencyfilters.TransparencyFilterIndexedColor;
 import 
org.apache.commons.imaging.formats.png.transparencyfilters.TransparencyFilterTrueColor;
 import org.apache.commons.imaging.icc.IccProfileParser;
-import org.apache.commons.imaging.util.IoUtils;
-
-import static org.apache.commons.imaging.ImagingConstants.*;
-import static org.apache.commons.imaging.common.BinaryFunctions.*;
 
 public class PngImageParser extends ImageParser {
     private static final String DEFAULT_EXTENSION = ".png";
@@ -117,17 +120,10 @@ public class PngImageParser extends Imag
 
     public boolean hasChuckType(final ByteSource byteSource, final ChunkType 
chunkType) 
             throws ImageReadException, IOException {
-        InputStream is = null;
-        boolean canThrow = false;
-        try {
-            is = byteSource.getInputStream();
-
+        try (InputStream is = byteSource.getInputStream()) {
             readSignature(is);
             final List<PngChunk> chunks = readChunks(is, new ChunkType[] { 
chunkType }, true);
-            canThrow = true;
             return !chunks.isEmpty();
-        } finally {
-            IoUtils.closeQuietly(canThrow, is);
         }
     }
 
@@ -228,18 +224,11 @@ public class PngImageParser extends Imag
 
     private List<PngChunk> readChunks(final ByteSource byteSource, final 
ChunkType[] chunkTypes,
             final boolean returnAfterFirst) throws ImageReadException, 
IOException {
-        InputStream is = null;
-        boolean canThrow = false;
-        try {
-            is = byteSource.getInputStream();
-
+        try (InputStream is = byteSource.getInputStream()) {
             readSignature(is);
 
             final List<PngChunk> ret = readChunks(is, chunkTypes, 
returnAfterFirst);
-            canThrow = true;
             return ret;
-        } finally {
-            IoUtils.closeQuietly(canThrow, is);
         }
     }
 

Modified: 
commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/png/PngWriter.java
URL: 
http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/png/PngWriter.java?rev=1759073&r1=1759072&r2=1759073&view=diff
==============================================================================
--- 
commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/png/PngWriter.java
 (original)
+++ 
commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/png/PngWriter.java
 Sat Sep  3 10:58:31 2016
@@ -33,7 +33,6 @@ import org.apache.commons.imaging.palett
 import org.apache.commons.imaging.palette.PaletteFactory;
 import org.apache.commons.imaging.palette.SimplePalette;
 import org.apache.commons.imaging.util.Debug;
-import org.apache.commons.imaging.util.IoUtils;
 
 class PngWriter {
     private final boolean verbose;
@@ -200,16 +199,13 @@ class PngWriter {
     }
 
     private byte[] deflate(final byte[] bytes) throws IOException {
-        final ByteArrayOutputStream baos = new ByteArrayOutputStream();
-        final DeflaterOutputStream dos = new DeflaterOutputStream(baos);
-        boolean canThrow = false;
-        try {
-            dos.write(bytes);
-            canThrow = true;
-        } finally {
-            IoUtils.closeQuietly(canThrow, dos);
+        try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
+            try (DeflaterOutputStream dos = new DeflaterOutputStream(baos)) {
+                dos.write(bytes);
+                // dos.flush() doesn't work - we must close it before 
baos.toByteArray()
+            }
+            return baos.toByteArray();
         }
-        return baos.toByteArray();
     }
     
     private boolean isValidISO_8859_1(final String s) {

Modified: 
commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/pnm/PnmImageParser.java
URL: 
http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/pnm/PnmImageParser.java?rev=1759073&r1=1759072&r2=1759073&view=diff
==============================================================================
--- 
commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/pnm/PnmImageParser.java
 (original)
+++ 
commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/pnm/PnmImageParser.java
 Sat Sep  3 10:58:31 2016
@@ -16,6 +16,9 @@
  */
 package org.apache.commons.imaging.formats.pnm;
 
+import static org.apache.commons.imaging.ImagingConstants.PARAM_KEY_FORMAT;
+import static org.apache.commons.imaging.common.BinaryFunctions.readByte;
+
 import java.awt.Dimension;
 import java.awt.image.BufferedImage;
 import java.io.IOException;
@@ -35,14 +38,10 @@ import org.apache.commons.imaging.ImageI
 import org.apache.commons.imaging.ImageParser;
 import org.apache.commons.imaging.ImageReadException;
 import org.apache.commons.imaging.ImageWriteException;
-import org.apache.commons.imaging.common.ImageMetadata;
 import org.apache.commons.imaging.common.ImageBuilder;
+import org.apache.commons.imaging.common.ImageMetadata;
 import org.apache.commons.imaging.common.bytesource.ByteSource;
 import org.apache.commons.imaging.palette.PaletteFactory;
-import org.apache.commons.imaging.util.IoUtils;
-
-import static org.apache.commons.imaging.ImagingConstants.*;
-import static org.apache.commons.imaging.common.BinaryFunctions.*;
 
 public class PnmImageParser extends ImageParser {
     private static final String DEFAULT_EXTENSION = ".pnm";
@@ -207,16 +206,9 @@ public class PnmImageParser extends Imag
 
     private FileInfo readHeader(final ByteSource byteSource)
             throws ImageReadException, IOException {
-        InputStream is = null;
-        boolean canThrow = false;
-        try {
-            is = byteSource.getInputStream();
-
+        try (InputStream is = byteSource.getInputStream()) {
             final FileInfo ret = readHeader(is);
-            canThrow = true;
             return ret;
-        } finally {
-            IoUtils.closeQuietly(canThrow, is);
         }
     }
 
@@ -304,11 +296,7 @@ public class PnmImageParser extends Imag
     @Override
     public BufferedImage getBufferedImage(final ByteSource byteSource, final 
Map<String, Object> params)
             throws ImageReadException, IOException {
-        InputStream is = null;
-        boolean canThrow = false;
-        try {
-            is = byteSource.getInputStream();
-
+        try (InputStream is = byteSource.getInputStream()) {
             final FileInfo info = readHeader(is);
 
             final int width = info.width;
@@ -320,10 +308,7 @@ public class PnmImageParser extends Imag
             info.readImage(imageBuilder, is);
 
             final BufferedImage ret = imageBuilder.getBufferedImage();
-            canThrow = true;
             return ret;
-        } finally {
-            IoUtils.closeQuietly(canThrow, is);
         }
     }
 

Modified: 
commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/psd/PsdImageParser.java
URL: 
http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/psd/PsdImageParser.java?rev=1759073&r1=1759072&r2=1759073&view=diff
==============================================================================
--- 
commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/psd/PsdImageParser.java
 (original)
+++ 
commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/psd/PsdImageParser.java
 Sat Sep  3 10:58:31 2016
@@ -16,6 +16,13 @@
  */
 package org.apache.commons.imaging.formats.psd;
 
+import static org.apache.commons.imaging.common.BinaryFunctions.read2Bytes;
+import static org.apache.commons.imaging.common.BinaryFunctions.read4Bytes;
+import static 
org.apache.commons.imaging.common.BinaryFunctions.readAndVerifyBytes;
+import static org.apache.commons.imaging.common.BinaryFunctions.readByte;
+import static org.apache.commons.imaging.common.BinaryFunctions.readBytes;
+import static org.apache.commons.imaging.common.BinaryFunctions.skipBytes;
+
 import java.awt.Dimension;
 import java.awt.image.BufferedImage;
 import java.io.ByteArrayInputStream;
@@ -45,9 +52,6 @@ import org.apache.commons.imaging.format
 import org.apache.commons.imaging.formats.psd.datareaders.CompressedDataReader;
 import org.apache.commons.imaging.formats.psd.datareaders.DataReader;
 import 
org.apache.commons.imaging.formats.psd.datareaders.UncompressedDataReader;
-import org.apache.commons.imaging.util.IoUtils;
-
-import static org.apache.commons.imaging.common.BinaryFunctions.*;
 
 public class PsdImageParser extends ImageParser {
     private static final String DEFAULT_EXTENSION = ".psd";
@@ -91,16 +95,9 @@ public class PsdImageParser extends Imag
 
     private PsdHeaderInfo readHeader(final ByteSource byteSource)
             throws ImageReadException, IOException {
-        InputStream is = null;
-        boolean canThrow = false;
-        try {
-            is = byteSource.getInputStream();
-
+        try (InputStream is = byteSource.getInputStream()) {
             final PsdHeaderInfo ret = readHeader(is);
-            canThrow = true;
             return ret;
-        } finally {
-            IoUtils.closeQuietly(canThrow, is);
         }
     }
 
@@ -240,25 +237,18 @@ public class PsdImageParser extends Imag
     private List<ImageResourceBlock> readImageResourceBlocks(
             final ByteSource byteSource, final int[] imageResourceIDs, final 
int maxBlocksToRead)
             throws ImageReadException, IOException {
-        InputStream imageStream = null;
-        InputStream resourceStream = null;
-        boolean canThrow = false;
-        try {
-            imageStream = byteSource.getInputStream();
+        try (InputStream imageStream = byteSource.getInputStream();
+                InputStream resourceStream = this.getInputStream(byteSource, 
PSD_SECTION_IMAGE_RESOURCES)) {
 
             final ImageContents imageContents = readImageContents(imageStream);
 
-            resourceStream = this.getInputStream(byteSource, 
PSD_SECTION_IMAGE_RESOURCES);
             final byte[] ImageResources = readBytes("ImageResources",
                     resourceStream, imageContents.ImageResourcesLength,
                     "Not a Valid PSD File");
 
             final List<ImageResourceBlock> ret = 
readImageResourceBlocks(ImageResources, imageResourceIDs,
                     maxBlocksToRead);
-            canThrow = true;
             return ret;
-        } finally {
-            IoUtils.closeQuietly(canThrow, imageStream, resourceStream);
         }
     }
 
@@ -326,14 +316,9 @@ public class PsdImageParser extends Imag
 
     private byte[] getData(final ByteSource byteSource, final int section)
             throws ImageReadException, IOException {
-        InputStream is = null;
-        boolean canThrow = false;
-        try {
-            is = byteSource.getInputStream();
-
+        try (InputStream is = byteSource.getInputStream()) {
             // PsdHeaderInfo header = readHeader(is);
             if (section == PSD_SECTION_HEADER) {
-                canThrow = true;
                 return readBytes("Header", is, PSD_HEADER_LENGTH,
                         "Not a Valid PSD File");
             }
@@ -343,7 +328,6 @@ public class PsdImageParser extends Imag
                     "Not a Valid PSD File", getByteOrder());
 
             if (section == PSD_SECTION_COLOR_MODE) {
-                canThrow = true;
                 return readBytes("ColorModeData", is, ColorModeDataLength,
                         "Not a Valid PSD File");
             }
@@ -356,7 +340,6 @@ public class PsdImageParser extends Imag
                     "Not a Valid PSD File", getByteOrder());
 
             if (section == PSD_SECTION_IMAGE_RESOURCES) {
-                canThrow = true;
                 return readBytes("ImageResources", is,
                         ImageResourcesLength, "Not a Valid PSD File");
             }
@@ -369,7 +352,6 @@ public class PsdImageParser extends Imag
                     is, "Not a Valid PSD File", getByteOrder());
 
             if (section == PSD_SECTION_LAYER_AND_MASK_DATA) {
-                canThrow = true;
                 return readBytes("LayerAndMaskData",
                         is, LayerAndMaskDataLength, "Not a Valid PSD File");
             }
@@ -387,9 +369,6 @@ public class PsdImageParser extends Imag
             // return readByteArray("LayerAndMaskData", LayerAndMaskDataLength,
             // is,
             // "Not a Valid PSD File");
-            canThrow = true;
-        } finally {
-            IoUtils.closeQuietly(canThrow, is);
         }
         throw new ImageReadException("getInputStream: Unknown Section: "
                 + section);
@@ -397,18 +376,10 @@ public class PsdImageParser extends Imag
 
     private ImageContents readImageContents(final ByteSource byteSource)
             throws ImageReadException, IOException {
-        InputStream is = null;
-        boolean canThrow = false;
-        try {
-            is = byteSource.getInputStream();
-
+        try (InputStream is = byteSource.getInputStream()) {
             final ImageContents imageContents = readImageContents(is);
-            canThrow = true;
             return imageContents;
-        } finally {
-            IoUtils.closeQuietly(canThrow, is);
         }
-
     }
 
     @Override
@@ -691,18 +662,12 @@ public class PsdImageParser extends Imag
                     + imageContents.Compression);
         }
         
-        InputStream is = null;
-        boolean canThrow = false;
-        try {
-            is = getInputStream(byteSource, PSD_SECTION_IMAGE_DATA);
+        try (InputStream is = getInputStream(byteSource, 
PSD_SECTION_IMAGE_DATA)) {
             fDataReader.readData(is, result, imageContents, this);
 
-            canThrow = true;
             // is.
             // ImageContents imageContents = readImageContents(is);
             // return imageContents;
-        } finally {
-            IoUtils.closeQuietly(canThrow, is);
         }
 
         return result;

Modified: 
commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/psd/datareaders/CompressedDataReader.java
URL: 
http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/psd/datareaders/CompressedDataReader.java?rev=1759073&r1=1759072&r2=1759073&view=diff
==============================================================================
--- 
commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/psd/datareaders/CompressedDataReader.java
 (original)
+++ 
commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/psd/datareaders/CompressedDataReader.java
 Sat Sep  3 10:58:31 2016
@@ -31,7 +31,6 @@ import org.apache.commons.imaging.common
 import org.apache.commons.imaging.formats.psd.ImageContents;
 import org.apache.commons.imaging.formats.psd.PsdHeaderInfo;
 import org.apache.commons.imaging.formats.psd.dataparsers.DataParser;
-import org.apache.commons.imaging.util.IoUtils;
 
 public class CompressedDataReader implements DataReader {
 
@@ -75,15 +74,10 @@ public class CompressedDataReader implem
                 final byte[] unpacked = new PackBits().decompress(packed, 
width);
                 final InputStream bais = new ByteArrayInputStream(unpacked);
                 final MyBitInputStream mbis = new MyBitInputStream(bais, 
ByteOrder.BIG_ENDIAN);
-                BitsToByteInputStream bbis = null;
-                boolean canThrow = false;
-                try {
-                    bbis = new BitsToByteInputStream(mbis, 8); // we want all 
samples to be bytes
+                // we want all samples to be bytes
+                try (BitsToByteInputStream bbis = new 
BitsToByteInputStream(mbis, 8)) {
                     final int[] scanline = bbis.readBitsArray(depth, width);
                     data[channel][y] = scanline;
-                    canThrow = true;
-                } finally {
-                    IoUtils.closeQuietly(canThrow, bbis);
                 }
             }
         }

Modified: 
commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/psd/datareaders/UncompressedDataReader.java
URL: 
http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/psd/datareaders/UncompressedDataReader.java?rev=1759073&r1=1759072&r2=1759073&view=diff
==============================================================================
--- 
commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/psd/datareaders/UncompressedDataReader.java
 (original)
+++ 
commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/psd/datareaders/UncompressedDataReader.java
 Sat Sep  3 10:58:31 2016
@@ -28,7 +28,6 @@ import org.apache.commons.imaging.common
 import org.apache.commons.imaging.formats.psd.ImageContents;
 import org.apache.commons.imaging.formats.psd.PsdHeaderInfo;
 import org.apache.commons.imaging.formats.psd.dataparsers.DataParser;
-import org.apache.commons.imaging.util.IoUtils;
 
 public class UncompressedDataReader implements DataReader {
 
@@ -52,11 +51,7 @@ public class UncompressedDataReader impl
         final int depth = header.depth;
         final MyBitInputStream mbis = new MyBitInputStream(is, 
ByteOrder.BIG_ENDIAN);
         // we want all samples to be bytes
-        BitsToByteInputStream bbis = null;
-        boolean canThrow = false;
-        try {
-            bbis = new BitsToByteInputStream(mbis, 8);
-
+        try (BitsToByteInputStream bbis = new BitsToByteInputStream(mbis, 8)) {
             final int[][][] data = new int[channelCount][height][width];
             for (int channel = 0; channel < channelCount; channel++) {
                 for (int y = 0; y < height; y++) {
@@ -69,9 +64,6 @@ public class UncompressedDataReader impl
             }
     
             dataParser.parseData(data, bi, imageContents);
-            canThrow = true;
-        } finally {
-            IoUtils.closeQuietly(canThrow, bbis);
         }
     }
 }

Modified: 
commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/rgbe/RgbeImageParser.java
URL: 
http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/rgbe/RgbeImageParser.java?rev=1759073&r1=1759072&r2=1759073&view=diff
==============================================================================
--- 
commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/rgbe/RgbeImageParser.java
 (original)
+++ 
commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/rgbe/RgbeImageParser.java
 Sat Sep  3 10:58:31 2016
@@ -38,7 +38,6 @@ import org.apache.commons.imaging.ImageP
 import org.apache.commons.imaging.ImageReadException;
 import org.apache.commons.imaging.common.ImageMetadata;
 import org.apache.commons.imaging.common.bytesource.ByteSource;
-import org.apache.commons.imaging.util.IoUtils;
 
 /**
  * Parser for Radiance HDR images
@@ -74,23 +73,16 @@ public class RgbeImageParser extends Ima
     @Override
     public ImageMetadata getMetadata(final ByteSource byteSource, final 
Map<String, Object> params)
             throws ImageReadException, IOException {
-        final RgbeInfo info = new RgbeInfo(byteSource);
-        boolean canThrow = false;
-        try {
+        try (RgbeInfo info = new RgbeInfo(byteSource)) {
             final ImageMetadata ret = info.getMetadata();
-            canThrow = true;
             return ret;
-        } finally {
-            IoUtils.closeQuietly(canThrow, info);
         }
     }
 
     @Override
     public ImageInfo getImageInfo(final ByteSource byteSource, final 
Map<String, Object> params)
             throws ImageReadException, IOException {
-        final RgbeInfo info = new RgbeInfo(byteSource);
-        boolean canThrow = false;
-        try {
+        try (RgbeInfo info = new RgbeInfo(byteSource)) {
             final ImageInfo ret = new ImageInfo(
                     getName(),
                     32, // todo may be 64 if double?
@@ -98,19 +90,14 @@ public class RgbeImageParser extends Ima
                     info.getHeight(), "image/vnd.radiance", 1, -1, -1, -1, -1,
                     info.getWidth(), false, false, false,
                     ImageInfo.ColorType.RGB, 
ImageInfo.CompressionAlgorithm.ADAPTIVE_RLE);
-            canThrow = true;
             return ret;
-        } finally {
-            IoUtils.closeQuietly(canThrow, info);
         }
     }
 
     @Override
     public BufferedImage getBufferedImage(final ByteSource byteSource, final 
Map<String, Object> params)
             throws ImageReadException, IOException {
-        final RgbeInfo info = new RgbeInfo(byteSource);
-        boolean canThrow = false;
-        try {
+        try (RgbeInfo info = new RgbeInfo(byteSource)) {
             // It is necessary to create our own BufferedImage here as the
             // org.apache.commons.imaging.common.IBufferedImageFactory 
interface does
             // not expose this complexity
@@ -124,24 +111,16 @@ public class RgbeImageParser extends Ima
                             new BandedSampleModel(buffer.getDataType(), info
                                     .getWidth(), info.getHeight(), 3), buffer,
                             new Point()), false, null);
-            canThrow = true;
             return ret;
-        } finally {
-            IoUtils.closeQuietly(canThrow, info);
         }
     }
 
     @Override
     public Dimension getImageSize(final ByteSource byteSource, final 
Map<String, Object> params)
             throws ImageReadException, IOException {
-        final RgbeInfo info = new RgbeInfo(byteSource);
-        boolean canThrow = false;
-        try {
+        try (RgbeInfo info = new RgbeInfo(byteSource)) {
             final Dimension ret = new Dimension(info.getWidth(), 
info.getHeight());
-            canThrow = true;
             return ret;
-        } finally {
-            IoUtils.closeQuietly(canThrow, info);
         }
     }
 

Modified: 
commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/tiff/TiffReader.java
URL: 
http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/tiff/TiffReader.java?rev=1759073&r1=1759072&r2=1759073&view=diff
==============================================================================
--- 
commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/tiff/TiffReader.java
 (original)
+++ 
commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/tiff/TiffReader.java
 Sat Sep  3 10:58:31 2016
@@ -16,6 +16,13 @@
  */
 package org.apache.commons.imaging.formats.tiff;
 
+import static org.apache.commons.imaging.common.BinaryFunctions.read2Bytes;
+import static org.apache.commons.imaging.common.BinaryFunctions.read4Bytes;
+import static org.apache.commons.imaging.common.BinaryFunctions.readByte;
+import static org.apache.commons.imaging.common.BinaryFunctions.readBytes;
+import static org.apache.commons.imaging.common.BinaryFunctions.skipBytes;
+import static 
org.apache.commons.imaging.formats.tiff.constants.TiffConstants.TIFF_ENTRY_MAX_VALUE_LENGTH;
+
 import java.io.IOException;
 import java.io.InputStream;
 import java.nio.ByteOrder;
@@ -37,10 +44,6 @@ import org.apache.commons.imaging.format
 import org.apache.commons.imaging.formats.tiff.constants.TiffTagConstants;
 import org.apache.commons.imaging.formats.tiff.fieldtypes.FieldType;
 import org.apache.commons.imaging.formats.tiff.taginfos.TagInfoLong;
-import org.apache.commons.imaging.util.IoUtils;
-
-import static org.apache.commons.imaging.common.BinaryFunctions.*;
-import static 
org.apache.commons.imaging.formats.tiff.constants.TiffConstants.*;
 
 public class TiffReader extends BinaryFileParser {
 
@@ -51,15 +54,9 @@ public class TiffReader extends BinaryFi
     }
 
     private TiffHeader readTiffHeader(final ByteSource byteSource) throws 
ImageReadException, IOException {
-        InputStream is = null;
-        boolean canThrow = false;
-        try {
-            is = byteSource.getInputStream();
+        try (InputStream is = byteSource.getInputStream()) {
             final TiffHeader ret = readTiffHeader(is);
-            canThrow = true;
             return ret;
-        } finally {
-            IoUtils.closeQuietly(canThrow, is);
         }
     }
     
@@ -133,15 +130,11 @@ public class TiffReader extends BinaryFi
         }
         visited.add(directoryOffset);
 
-        InputStream is = null;
-        boolean canThrow = false;
-        try {
+        try (InputStream is = byteSource.getInputStream()) {
             if (directoryOffset >= byteSource.getLength()) {
-                canThrow = true;
                 return true;
             }
 
-            is = byteSource.getInputStream();
             skipBytes(is, directoryOffset);
 
             final List<TiffField> fields = new ArrayList<>();
@@ -153,7 +146,6 @@ public class TiffReader extends BinaryFi
                 if (strict) {
                     throw e;
                 } else {
-                    canThrow = true;
                     return true;
                 }
             }
@@ -208,7 +200,6 @@ public class TiffReader extends BinaryFi
                 fields.add(field);
 
                 if (!listener.addField(field)) {
-                    canThrow = true;
                     return true;
                 }
             }
@@ -233,7 +224,6 @@ public class TiffReader extends BinaryFi
             }
 
             if (!listener.addDirectory(directory)) {
-                canThrow = true;
                 return true;
             }
 
@@ -280,10 +270,7 @@ public class TiffReader extends BinaryFi
                         dirType + 1, formatCompliance, listener, visited);
             }
 
-            canThrow = true;
             return true;
-        } finally {
-            IoUtils.closeQuietly(canThrow, is);
         }
     }
 

Modified: 
commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/wbmp/WbmpImageParser.java
URL: 
http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/wbmp/WbmpImageParser.java?rev=1759073&r1=1759072&r2=1759073&view=diff
==============================================================================
--- 
commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/wbmp/WbmpImageParser.java
 (original)
+++ 
commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/wbmp/WbmpImageParser.java
 Sat Sep  3 10:58:31 2016
@@ -15,6 +15,10 @@
 
 package org.apache.commons.imaging.formats.wbmp;
 
+import static org.apache.commons.imaging.ImagingConstants.PARAM_KEY_FORMAT;
+import static org.apache.commons.imaging.common.BinaryFunctions.readByte;
+import static org.apache.commons.imaging.common.BinaryFunctions.readBytes;
+
 import java.awt.Dimension;
 import java.awt.image.BufferedImage;
 import java.awt.image.DataBuffer;
@@ -39,10 +43,6 @@ import org.apache.commons.imaging.ImageR
 import org.apache.commons.imaging.ImageWriteException;
 import org.apache.commons.imaging.common.ImageMetadata;
 import org.apache.commons.imaging.common.bytesource.ByteSource;
-import org.apache.commons.imaging.util.IoUtils;
-
-import static org.apache.commons.imaging.ImagingConstants.*;
-import static org.apache.commons.imaging.common.BinaryFunctions.*;
 
 public class WbmpImageParser extends ImageParser {
     private static final String DEFAULT_EXTENSION = ".wbmp";
@@ -157,15 +157,9 @@ public class WbmpImageParser extends Ima
 
     private WbmpHeader readWbmpHeader(final ByteSource byteSource)
             throws ImageReadException, IOException {
-        InputStream is = null;
-        boolean canThrow = false;
-        try {
-            is = byteSource.getInputStream();
+        try (InputStream is = byteSource.getInputStream()) {
             final WbmpHeader ret = readWbmpHeader(is);
-            canThrow = true;
             return ret;
-        } finally {
-            IoUtils.closeQuietly(canThrow, is);
         }
     }
 
@@ -217,16 +211,10 @@ public class WbmpImageParser extends Ima
     @Override
     public final BufferedImage getBufferedImage(final ByteSource byteSource,
             final Map<String, Object> params) throws ImageReadException, 
IOException {
-        InputStream is = null;
-        boolean canThrow = false;
-        try {
-            is = byteSource.getInputStream();
+        try (InputStream is = byteSource.getInputStream()) {
             final WbmpHeader wbmpHeader = readWbmpHeader(is);
             final BufferedImage ret = readImage(wbmpHeader, is);
-            canThrow = true;
             return ret;
-        } finally {
-            IoUtils.closeQuietly(canThrow, is);
         }
     }
 

Modified: 
commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/xbm/XbmImageParser.java
URL: 
http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/xbm/XbmImageParser.java?rev=1759073&r1=1759072&r2=1759073&view=diff
==============================================================================
--- 
commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/xbm/XbmImageParser.java
 (original)
+++ 
commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/xbm/XbmImageParser.java
 Sat Sep  3 10:58:31 2016
@@ -15,6 +15,8 @@
 
 package org.apache.commons.imaging.formats.xbm;
 
+import static org.apache.commons.imaging.ImagingConstants.PARAM_KEY_FORMAT;
+
 import java.awt.Dimension;
 import java.awt.image.BufferedImage;
 import java.awt.image.ColorModel;
@@ -45,9 +47,6 @@ import org.apache.commons.imaging.ImageW
 import org.apache.commons.imaging.common.BasicCParser;
 import org.apache.commons.imaging.common.ImageMetadata;
 import org.apache.commons.imaging.common.bytesource.ByteSource;
-import org.apache.commons.imaging.util.IoUtils;
-
-import static org.apache.commons.imaging.ImagingConstants.*;
 
 public class XbmImageParser extends ImageParser {
     private static final String DEFAULT_EXTENSION = ".xbm";
@@ -141,10 +140,7 @@ public class XbmImageParser extends Imag
 
     private XbmParseResult parseXbmHeader(final ByteSource byteSource)
             throws ImageReadException, IOException {
-        InputStream is = null;
-        boolean canThrow = false;
-        try {
-            is = byteSource.getInputStream();
+        try (InputStream is = byteSource.getInputStream()) {
             final Map<String, String> defines = new HashMap<>();
             final ByteArrayOutputStream preprocessedFile = 
BasicCParser.preprocess(
                     is, null, defines);
@@ -175,10 +171,7 @@ public class XbmImageParser extends Imag
             xbmParseResult.cParser = new BasicCParser(new ByteArrayInputStream(
                     preprocessedFile.toByteArray()));
             xbmParseResult.xbmHeader = new XbmHeader(width, height, xHot, 
yHot);
-            canThrow = true;
             return xbmParseResult;
-        } finally {
-            IoUtils.closeQuietly(canThrow, is);
         }
     }
 

Modified: 
commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/xpm/XpmImageParser.java
URL: 
http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/xpm/XpmImageParser.java?rev=1759073&r1=1759072&r2=1759073&view=diff
==============================================================================
--- 
commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/xpm/XpmImageParser.java
 (original)
+++ 
commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/xpm/XpmImageParser.java
 Sat Sep  3 10:58:31 2016
@@ -15,6 +15,8 @@
 
 package org.apache.commons.imaging.formats.xpm;
 
+import static org.apache.commons.imaging.ImagingConstants.PARAM_KEY_FORMAT;
+
 import java.awt.Dimension;
 import java.awt.image.BufferedImage;
 import java.awt.image.ColorModel;
@@ -50,9 +52,6 @@ import org.apache.commons.imaging.common
 import org.apache.commons.imaging.common.bytesource.ByteSource;
 import org.apache.commons.imaging.palette.PaletteFactory;
 import org.apache.commons.imaging.palette.SimplePalette;
-import org.apache.commons.imaging.util.IoUtils;
-
-import static org.apache.commons.imaging.ImagingConstants.*;
 
 public class XpmImageParser extends ImageParser {
     private static final String DEFAULT_EXTENSION = ".xpm";
@@ -80,11 +79,8 @@ public class XpmImageParser extends Imag
                     throw new ImageReadException("Couldn't find rgb.txt in our 
resources");
                 }
                 final Map<String, Integer> colors = new HashMap<>();
-                BufferedReader reader = null;
-                boolean canThrow = false;
-                try {
-                    reader = new BufferedReader(new 
InputStreamReader(rgbTxtStream,
-                            "US-ASCII"));
+                try (InputStreamReader isReader = new 
InputStreamReader(rgbTxtStream, "US-ASCII");
+                        BufferedReader reader = new BufferedReader(isReader)) {
                     String line;
                     while ((line = reader.readLine()) != null) {
                         if (line.charAt(0) == '!') {
@@ -101,9 +97,6 @@ public class XpmImageParser extends Imag
                             throw new ImageReadException("Couldn't parse color 
in rgb.txt", nfe);
                         }
                     }
-                    canThrow = true;
-                } finally {
-                    IoUtils.closeQuietly(canThrow, reader);
                 }
                 colorNames = colors;
             } catch (final IOException ioException) {
@@ -253,10 +246,7 @@ public class XpmImageParser extends Imag
 
     private XpmParseResult parseXpmHeader(final ByteSource byteSource)
             throws ImageReadException, IOException {
-        InputStream is = null;
-        boolean canThrow = false;
-        try {
-            is = byteSource.getInputStream();
+        try (InputStream is = byteSource.getInputStream()) {
             final StringBuilder firstComment = new StringBuilder();
             final ByteArrayOutputStream preprocessedFile = 
BasicCParser.preprocess(
                     is, firstComment, null);
@@ -269,10 +259,7 @@ public class XpmImageParser extends Imag
             xpmParseResult.cParser = new BasicCParser(new ByteArrayInputStream(
                     preprocessedFile.toByteArray()));
             xpmParseResult.xpmHeader = parseXpmHeader(xpmParseResult.cParser);
-            canThrow = true;
             return xpmParseResult;
-        } finally {
-            IoUtils.closeQuietly(canThrow, is);
         }
     }
 

Modified: 
commons/proper/imaging/trunk/src/test/java/org/apache/commons/imaging/formats/jpeg/iptc/IptcAddTest.java
URL: 
http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/test/java/org/apache/commons/imaging/formats/jpeg/iptc/IptcAddTest.java?rev=1759073&r1=1759072&r2=1759073&view=diff
==============================================================================
--- 
commons/proper/imaging/trunk/src/test/java/org/apache/commons/imaging/formats/jpeg/iptc/IptcAddTest.java
 (original)
+++ 
commons/proper/imaging/trunk/src/test/java/org/apache/commons/imaging/formats/jpeg/iptc/IptcAddTest.java
 Sat Sep  3 10:58:31 2016
@@ -35,7 +35,6 @@ import org.apache.commons.imaging.common
 import org.apache.commons.imaging.common.bytesource.ByteSourceFile;
 import org.apache.commons.imaging.formats.jpeg.JpegImageParser;
 import org.apache.commons.imaging.formats.jpeg.JpegPhotoshopMetadata;
-import org.apache.commons.imaging.util.IoUtils;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.junit.runners.Parameterized;
@@ -90,15 +89,9 @@ public class IptcAddTest extends IptcBas
         final PhotoshopApp13Data newData = new PhotoshopApp13Data(newRecords, 
newBlocks);
 
         final File updated = createTempFile(imageFile.getName() + 
".iptc.add.", ".jpg");
-        OutputStream os = null;
-        boolean canThrow = false;
-        try {
-            os = new FileOutputStream(updated);
-            os = new BufferedOutputStream(os);
+        try (FileOutputStream fos = new FileOutputStream(updated);
+                OutputStream os = new BufferedOutputStream(fos)) {
             new JpegIptcRewriter().writeIPTC(byteSource, os, newData);
-            canThrow = true;
-        } finally {
-            IoUtils.closeQuietly(canThrow, os);
         }
 
         final ByteSource updateByteSource = new ByteSourceFile(updated);

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=1759073&r1=1759072&r2=1759073&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
 Sat Sep  3 10:58:31 2016
@@ -38,7 +38,6 @@ import org.apache.commons.imaging.common
 import org.apache.commons.imaging.common.bytesource.ByteSourceFile;
 import org.apache.commons.imaging.formats.jpeg.JpegImageParser;
 import org.apache.commons.imaging.formats.jpeg.JpegPhotoshopMetadata;
-import org.apache.commons.imaging.util.IoUtils;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.junit.runners.Parameterized;
@@ -116,16 +115,10 @@ public class IptcUpdateTest extends Iptc
 
         final File updated = createTempFile(imageFile.getName()
                 + ".iptc.insert.", ".jpg");
-        OutputStream os = null;
-        boolean canThrow = false;
-        try {
-            os = new FileOutputStream(updated);
-            os = new BufferedOutputStream(os);
+        try (FileOutputStream fos = new FileOutputStream(updated);
+                OutputStream os = new BufferedOutputStream(fos)) {
             new JpegIptcRewriter().writeIPTC(new ByteSourceFile(
                     noIptcFile), os, newData);
-            canThrow = true;
-        } finally {
-            IoUtils.closeQuietly(canThrow, os);
         }
 
         final ByteSource updateByteSource = new ByteSourceFile(updated);
@@ -170,15 +163,9 @@ public class IptcUpdateTest extends Iptc
     public File writeIptc(ByteSource byteSource, PhotoshopApp13Data newData) 
throws IOException, ImageReadException, ImageWriteException {
         final File updated = createTempFile(imageFile.getName()
                 + ".iptc.update.", ".jpg");
-        OutputStream os = null;
-        boolean canThrow = false;
-        try {
-            os = new FileOutputStream(updated);
-            os = new BufferedOutputStream(os);
+        try (FileOutputStream fos = new FileOutputStream(updated);
+                OutputStream os = new BufferedOutputStream(fos)) {
             new JpegIptcRewriter().writeIPTC(byteSource, os, newData);
-            canThrow = true;
-        } finally {
-            IoUtils.closeQuietly(canThrow, os);
         }
         return updated;
     }

Modified: 
commons/proper/imaging/trunk/src/test/java/org/apache/commons/imaging/formats/jpeg/xmp/JpegXmpRewriteTest.java
URL: 
http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/test/java/org/apache/commons/imaging/formats/jpeg/xmp/JpegXmpRewriteTest.java?rev=1759073&r1=1759072&r2=1759073&view=diff
==============================================================================
--- 
commons/proper/imaging/trunk/src/test/java/org/apache/commons/imaging/formats/jpeg/xmp/JpegXmpRewriteTest.java
 (original)
+++ 
commons/proper/imaging/trunk/src/test/java/org/apache/commons/imaging/formats/jpeg/xmp/JpegXmpRewriteTest.java
 Sat Sep  3 10:58:31 2016
@@ -32,7 +32,6 @@ import java.util.Map;
 import org.apache.commons.imaging.common.bytesource.ByteSource;
 import org.apache.commons.imaging.common.bytesource.ByteSourceFile;
 import org.apache.commons.imaging.formats.jpeg.JpegImageParser;
-import org.apache.commons.imaging.util.IoUtils;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.junit.runners.Parameterized;
@@ -62,15 +61,9 @@ public class JpegXmpRewriteTest extends
         {
             // test remove
 
-            OutputStream os = null;
-            boolean canThrow = false;
-            try {
-                os = new FileOutputStream(noXmpFile);
-                os = new BufferedOutputStream(os);
+            try (FileOutputStream fos = new FileOutputStream(noXmpFile);
+                    OutputStream os = new BufferedOutputStream(fos)) {
                 new JpegXmpRewriter().removeXmpXml(byteSource, os);
-                canThrow = true;
-            } finally {
-                IoUtils.closeQuietly(canThrow, os);
             }
 
             // Debug.debug("Source Segments:");
@@ -86,16 +79,9 @@ public class JpegXmpRewriteTest extends
 
             final String newXmpXml = "test";
             final File updated = createTempFile(imageFile.getName() + ".", 
".jpg");
-            OutputStream os = null;
-            boolean canThrow = false;
-            try {
-                os = new FileOutputStream(updated);
-                os = new BufferedOutputStream(os);
-                new JpegXmpRewriter().updateXmpXml(byteSource, os,
-                        newXmpXml);
-                canThrow = true;
-            } finally {
-                IoUtils.closeQuietly(canThrow, os);
+            try (FileOutputStream fos = new FileOutputStream(updated);
+                    OutputStream os = new BufferedOutputStream(fos)) {
+                new JpegXmpRewriter().updateXmpXml(byteSource, os, newXmpXml);
             }
 
             // Debug.debug("Source Segments:");
@@ -112,16 +98,10 @@ public class JpegXmpRewriteTest extends
 
             final String newXmpXml = "test";
             final File updated = createTempFile(imageFile.getName() + ".", 
".jpg");
-            OutputStream os = null;
-            boolean canThrow = false;
-            try {
-                os = new FileOutputStream(updated);
-                os = new BufferedOutputStream(os);
+            try (FileOutputStream fos = new FileOutputStream(updated);
+                    OutputStream os = new BufferedOutputStream(fos)) {
                 new JpegXmpRewriter().updateXmpXml(new ByteSourceFile(
                         noXmpFile), os, newXmpXml);
-                canThrow = true;
-            } finally {
-                IoUtils.closeQuietly(canThrow, os);
             }
 
             // Debug.debug("Source Segments:");


Reply via email to