You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2023/05/14 16:24:21 UTC

[commons-imaging] 10/14: Use try-with-resources

This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-imaging.git

commit 4dc2fc5dcc1b554d649b7d642e164243362db0c8
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sun May 14 11:34:18 2023 -0400

    Use try-with-resources
    
    Format tweak
---
 .../org/apache/commons/imaging/formats/jpeg/decoder/JpegDecoder.java | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/src/main/java/org/apache/commons/imaging/formats/jpeg/decoder/JpegDecoder.java b/src/main/java/org/apache/commons/imaging/formats/jpeg/decoder/JpegDecoder.java
index d91f3f0a..4152b2c3 100644
--- a/src/main/java/org/apache/commons/imaging/formats/jpeg/decoder/JpegDecoder.java
+++ b/src/main/java/org/apache/commons/imaging/formats/jpeg/decoder/JpegDecoder.java
@@ -414,8 +414,7 @@ public class JpegDecoder extends BinaryFileParser implements JpegUtils.Visitor {
 
     @Override
     public void visitSOS(final int marker, final byte[] markerBytes, final byte[] imageData) {
-        final ByteArrayInputStream is = new ByteArrayInputStream(imageData);
-        try {
+        try (ByteArrayInputStream is = new ByteArrayInputStream(imageData)) {
             // read the scan header
             final int segmentLength = read2Bytes("segmentLength", is,"Not a Valid JPEG File", getByteOrder());
             final byte[] sosSegmentBytes = readBytes("SosSegment", is, segmentLength - 2, "Not a Valid JPEG File");
@@ -547,7 +546,7 @@ public class JpegDecoder extends BinaryFileParser implements JpegUtils.Visitor {
             ioException = ioEx;
         } catch (final RuntimeException ex) {
             // Corrupt images can throw NPE and IOOBE
-            imageReadException = new ImageReadException("Error parsing JPEG",ex);
+            imageReadException = new ImageReadException("Error parsing JPEG", ex);
         }
     }
 }