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 a31f9f6b5bce1afa745f720d686f3c730cab5cba
Author: Gary Gregory <garydgreg...@gmail.com>
AuthorDate: Sun May 14 17:25:23 2023 -0400

    Use ImagingException
---
 .../imaging/common/bytesource/ByteSourceArray.java |   6 +-
 .../imaging/common/bytesource/ByteSourceFile.java  |   3 +-
 .../common/bytesource/ByteSourceInputStream.java   |   5 +-
 .../imaging/common/mylzw/MyLzwCompressor.java      |   5 +-
 .../imaging/common/mylzw/MyLzwDecompressor.java    |   4 +-
 .../commons/imaging/formats/pnm/FileInfo.java      |  10 +-
 .../commons/imaging/formats/pnm/PbmFileInfo.java   |   7 +-
 .../imaging/formats/pnm/WhiteSpaceReader.java      |   4 +-
 .../imaging/formats/rgbe/InfoHeaderReader.java     |   4 +-
 .../formats/tiff/datareaders/BitInputStream.java   |  10 +-
 .../tiff/write/TiffImageWriterLossless.java        |   4 +-
 .../commons/imaging/icc/IccProfileParser.java      | 245 ++++++++++-----------
 12 files changed, 160 insertions(+), 147 deletions(-)

diff --git 
a/src/main/java/org/apache/commons/imaging/common/bytesource/ByteSourceArray.java
 
b/src/main/java/org/apache/commons/imaging/common/bytesource/ByteSourceArray.java
index ddbcbb13..cf246dc3 100644
--- 
a/src/main/java/org/apache/commons/imaging/common/bytesource/ByteSourceArray.java
+++ 
b/src/main/java/org/apache/commons/imaging/common/bytesource/ByteSourceArray.java
@@ -21,6 +21,8 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.util.Arrays;
 
+import org.apache.commons.imaging.ImagingException;
+
 public class ByteSourceArray extends ByteSource {
     private final byte[] bytes;
 
@@ -39,12 +41,12 @@ public class ByteSourceArray extends ByteSource {
     }
 
     @Override
-    public byte[] getBlock(final long startLong, final int length) throws 
IOException {
+    public byte[] getBlock(final long startLong, final int length) throws 
ImagingException {
         final int start = (int) startLong;
         // We include a separate check for int overflow.
         if ((start < 0) || (length < 0) || (start + length < 0)
                 || (start + length > bytes.length)) {
-            throw new IOException("Could not read block (block start: " + start
+            throw new ImagingException("Could not read block (block start: " + 
start
                     + ", block length: " + length + ", data length: "
                     + bytes.length + ").");
         }
diff --git 
a/src/main/java/org/apache/commons/imaging/common/bytesource/ByteSourceFile.java
 
b/src/main/java/org/apache/commons/imaging/common/bytesource/ByteSourceFile.java
index e9b253d4..b9a8910e 100644
--- 
a/src/main/java/org/apache/commons/imaging/common/bytesource/ByteSourceFile.java
+++ 
b/src/main/java/org/apache/commons/imaging/common/bytesource/ByteSourceFile.java
@@ -24,6 +24,7 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.io.RandomAccessFile;
 
+import org.apache.commons.imaging.ImagingException;
 import org.apache.commons.imaging.common.BinaryFunctions;
 
 public class ByteSourceFile extends ByteSource {
@@ -54,7 +55,7 @@ public class ByteSourceFile extends ByteSource {
             // We include a separate check for int overflow.
             if ((start < 0) || (length < 0) || (start + length < 0)
                     || (start + length > raf.length())) {
-                throw new IOException("Could not read block (block start: "
+                throw new ImagingException("Could not read block (block start: 
"
                         + start + ", block length: " + length
                         + ", data length: " + raf.length() + ").");
             }
diff --git 
a/src/main/java/org/apache/commons/imaging/common/bytesource/ByteSourceInputStream.java
 
b/src/main/java/org/apache/commons/imaging/common/bytesource/ByteSourceInputStream.java
index c28e6ae1..e4bdc947 100644
--- 
a/src/main/java/org/apache/commons/imaging/common/bytesource/ByteSourceInputStream.java
+++ 
b/src/main/java/org/apache/commons/imaging/common/bytesource/ByteSourceInputStream.java
@@ -23,6 +23,7 @@ import java.io.InputStream;
 import java.util.Arrays;
 import java.util.Objects;
 
+import org.apache.commons.imaging.ImagingException;
 import org.apache.commons.imaging.common.Allocator;
 import org.apache.commons.imaging.common.BinaryFunctions;
 
@@ -196,7 +197,7 @@ public class ByteSourceInputStream extends ByteSource {
         if ((blockStart < 0) || (blockLength < 0)
                 || (blockStart + blockLength < 0)
                 || (blockStart + blockLength > getLength())) {
-            throw new IOException("Could not read block (block start: "
+            throw new ImagingException("Could not read block (block start: "
                     + blockStart + ", block length: " + blockLength
                     + ", data length: " + streamLength + ").");
         }
@@ -209,7 +210,7 @@ public class ByteSourceInputStream extends ByteSource {
         while (true) {
             final int read = cis.read(bytes, total, bytes.length - total);
             if (read < 1) {
-                throw new IOException("Could not read block.");
+                throw new ImagingException("Could not read block.");
             }
             total += read;
             if (total >= blockLength) {
diff --git 
a/src/main/java/org/apache/commons/imaging/common/mylzw/MyLzwCompressor.java 
b/src/main/java/org/apache/commons/imaging/common/mylzw/MyLzwCompressor.java
index 5e00ea27..13994d9e 100644
--- a/src/main/java/org/apache/commons/imaging/common/mylzw/MyLzwCompressor.java
+++ b/src/main/java/org/apache/commons/imaging/common/mylzw/MyLzwCompressor.java
@@ -22,6 +22,7 @@ import java.nio.ByteOrder;
 import java.util.HashMap;
 import java.util.Map;
 
+import org.apache.commons.imaging.ImagingException;
 import org.apache.commons.imaging.common.Allocator;
 
 public class MyLzwCompressor {
@@ -165,11 +166,11 @@ public class MyLzwCompressor {
     }
 
     private int codeFromString(final byte[] bytes, final int start, final int 
length)
-            throws IOException {
+            throws ImagingException {
         final ByteArray key = arrayToKey(bytes, start, length);
         final Integer code = map.get(key);
         if (code == null) {
-            throw new IOException("CodeFromString");
+            throw new ImagingException("CodeFromString");
         }
         return code;
     }
diff --git 
a/src/main/java/org/apache/commons/imaging/common/mylzw/MyLzwDecompressor.java 
b/src/main/java/org/apache/commons/imaging/common/mylzw/MyLzwDecompressor.java
index 77755a1e..7584e3bc 100644
--- 
a/src/main/java/org/apache/commons/imaging/common/mylzw/MyLzwDecompressor.java
+++ 
b/src/main/java/org/apache/commons/imaging/common/mylzw/MyLzwDecompressor.java
@@ -181,9 +181,9 @@ public final class MyLzwDecompressor {
         return code < codes;
     }
 
-    private byte[] stringFromCode(final int code) throws IOException {
+    private byte[] stringFromCode(final int code) throws ImagingException {
         if ((code >= codes) || (code < 0)) {
-            throw new IOException("Bad Code: " + code + " codes: " + codes
+            throw new ImagingException("Bad Code: " + code + " codes: " + codes
                     + " code_size: " + codeSize + ", table: " + table.length);
         }
         return table[code];
diff --git a/src/main/java/org/apache/commons/imaging/formats/pnm/FileInfo.java 
b/src/main/java/org/apache/commons/imaging/formats/pnm/FileInfo.java
index 728674a2..27c2f525 100644
--- a/src/main/java/org/apache/commons/imaging/formats/pnm/FileInfo.java
+++ b/src/main/java/org/apache/commons/imaging/formats/pnm/FileInfo.java
@@ -21,25 +21,28 @@ import java.io.InputStream;
 
 import org.apache.commons.imaging.ImageFormat;
 import org.apache.commons.imaging.ImageInfo;
+import org.apache.commons.imaging.ImagingException;
 import org.apache.commons.imaging.common.ImageBuilder;
 
 abstract class FileInfo {
+
     static int readSample(final InputStream is, final int bytesPerSample) 
throws IOException {
         int sample = 0;
         for (int i = 0; i < bytesPerSample; i++) {
             final int nextByte = is.read();
             if (nextByte < 0) {
-                throw new IOException("PNM: Unexpected EOF");
+                throw new ImagingException("PNM: Unexpected EOF");
             }
             sample <<= 8;
             sample |= nextByte;
         }
         return sample;
     }
-    static int scaleSample(int sample, final float scale, final int max) 
throws IOException {
+
+    static int scaleSample(int sample, final float scale, final int max) 
throws ImagingException {
         if (sample < 0) {
             // Even netpbm tools break for files like this
-            throw new IOException("Negative pixel values are invalid in PNM 
files");
+            throw new ImagingException("Negative pixel values are invalid in 
PNM files");
         }
         if (sample > max) {
             // invalid values -> black
@@ -47,6 +50,7 @@ abstract class FileInfo {
         }
         return (int) ((sample * scale / max) + 0.5f);
     }
+
     final int width;
 
     final int height;
diff --git 
a/src/main/java/org/apache/commons/imaging/formats/pnm/PbmFileInfo.java 
b/src/main/java/org/apache/commons/imaging/formats/pnm/PbmFileInfo.java
index 7c93dad3..aeb2b801 100644
--- a/src/main/java/org/apache/commons/imaging/formats/pnm/PbmFileInfo.java
+++ b/src/main/java/org/apache/commons/imaging/formats/pnm/PbmFileInfo.java
@@ -22,6 +22,7 @@ import java.io.InputStream;
 import org.apache.commons.imaging.ImageFormat;
 import org.apache.commons.imaging.ImageFormats;
 import org.apache.commons.imaging.ImageInfo;
+import org.apache.commons.imaging.ImagingException;
 
 class PbmFileInfo extends FileInfo {
     private int bitCache;
@@ -66,7 +67,7 @@ class PbmFileInfo extends FileInfo {
         if (bitsInCache < 1) {
             final int bits = is.read();
             if (bits < 0) {
-                throw new IOException("PBM: Unexpected EOF");
+                throw new ImagingException("PBM: Unexpected EOF");
             }
             bitCache = 0xff & bits;
             bitsInCache += 8;
@@ -82,7 +83,7 @@ class PbmFileInfo extends FileInfo {
         if (bit == 1) {
             return 0xff000000;
         }
-        throw new IOException("PBM: bad bit: " + bit);
+        throw new ImagingException("PBM: bad bit: " + bit);
     }
 
     @Override
@@ -94,7 +95,7 @@ class PbmFileInfo extends FileInfo {
         if (bit == 1) {
             return 0xffffffff;
         }
-        throw new IOException("PBM: bad bit: " + bit);
+        throw new ImagingException("PBM: bad bit: " + bit);
     }
 
     @Override
diff --git 
a/src/main/java/org/apache/commons/imaging/formats/pnm/WhiteSpaceReader.java 
b/src/main/java/org/apache/commons/imaging/formats/pnm/WhiteSpaceReader.java
index 636adab3..06bd7190 100644
--- a/src/main/java/org/apache/commons/imaging/formats/pnm/WhiteSpaceReader.java
+++ b/src/main/java/org/apache/commons/imaging/formats/pnm/WhiteSpaceReader.java
@@ -19,6 +19,8 @@ package org.apache.commons.imaging.formats.pnm;
 import java.io.IOException;
 import java.io.InputStream;
 
+import org.apache.commons.imaging.ImagingException;
+
 class WhiteSpaceReader {
     private final InputStream is;
 
@@ -40,7 +42,7 @@ class WhiteSpaceReader {
     private char read() throws IOException {
         final int result = is.read();
         if (result < 0) {
-            throw new IOException("PNM: Unexpected EOF");
+            throw new ImagingException("PNM: Unexpected EOF");
         }
         return (char) result;
     }
diff --git 
a/src/main/java/org/apache/commons/imaging/formats/rgbe/InfoHeaderReader.java 
b/src/main/java/org/apache/commons/imaging/formats/rgbe/InfoHeaderReader.java
index fff7e7f3..f141af54 100644
--- 
a/src/main/java/org/apache/commons/imaging/formats/rgbe/InfoHeaderReader.java
+++ 
b/src/main/java/org/apache/commons/imaging/formats/rgbe/InfoHeaderReader.java
@@ -19,6 +19,8 @@ package org.apache.commons.imaging.formats.rgbe;
 import java.io.IOException;
 import java.io.InputStream;
 
+import org.apache.commons.imaging.ImagingException;
+
 class InfoHeaderReader {
     private final InputStream is;
 
@@ -29,7 +31,7 @@ class InfoHeaderReader {
     private char read() throws IOException {
         final int result = is.read();
         if (result < 0) {
-            throw new IOException("HDR: Unexpected EOF");
+            throw new ImagingException("HDR: Unexpected EOF");
         }
         return (char) result;
     }
diff --git 
a/src/main/java/org/apache/commons/imaging/formats/tiff/datareaders/BitInputStream.java
 
b/src/main/java/org/apache/commons/imaging/formats/tiff/datareaders/BitInputStream.java
index c3e890dc..b1e464e5 100644
--- 
a/src/main/java/org/apache/commons/imaging/formats/tiff/datareaders/BitInputStream.java
+++ 
b/src/main/java/org/apache/commons/imaging/formats/tiff/datareaders/BitInputStream.java
@@ -21,6 +21,8 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.nio.ByteOrder;
 
+import org.apache.commons.imaging.ImagingException;
+
 /**
  * Input stream reading 1-8, 16, 24 or 32 bits, starting from the most 
significant bit, but incapable of reading
  * non-aligned and < 8 bit fields across byte boundaries.
@@ -47,7 +49,7 @@ class BitInputStream extends FilterInputStream {
     @Override
     public int read() throws IOException {
         if (cacheBitsRemaining > 0) {
-            throw new IOException("BitInputStream: incomplete bit read");
+            throw new ImagingException("BitInputStream: incomplete bit read");
         }
         return in.read();
     }
@@ -61,7 +63,7 @@ class BitInputStream extends FilterInputStream {
                 bytesRead++;
             }
             if (count > cacheBitsRemaining) {
-                throw new IOException("BitInputStream: can't read bit fields 
across bytes");
+                throw new ImagingException("BitInputStream: can't read bit 
fields across bytes");
             }
 
             // int bits_to_shift = cache_bits_remaining - count;
@@ -87,7 +89,7 @@ class BitInputStream extends FilterInputStream {
 
         }
         if (cacheBitsRemaining > 0) {
-            throw new IOException("BitInputStream: incomplete bit read");
+            throw new ImagingException("BitInputStream: incomplete bit read");
         }
 
         if (count == 8) {
@@ -129,6 +131,6 @@ class BitInputStream extends FilterInputStream {
             }
         }
 
-        throw new IOException("BitInputStream: unknown error");
+        throw new ImagingException("BitInputStream: unknown error");
     }
 }
diff --git 
a/src/main/java/org/apache/commons/imaging/formats/tiff/write/TiffImageWriterLossless.java
 
b/src/main/java/org/apache/commons/imaging/formats/tiff/write/TiffImageWriterLossless.java
index 12703efd..2aab2f0b 100644
--- 
a/src/main/java/org/apache/commons/imaging/formats/tiff/write/TiffImageWriterLossless.java
+++ 
b/src/main/java/org/apache/commons/imaging/formats/tiff/write/TiffImageWriterLossless.java
@@ -59,7 +59,7 @@ public class TiffImageWriterLossless extends 
TiffImageWriterBase {
         @Override
         public void write(final byte[] b, final int off, final int len) throws 
IOException {
             if (index + len > buffer.length) {
-                throw new IOException("Buffer overflow.");
+                throw new ImagingException("Buffer overflow.");
             }
             System.arraycopy(b, off, buffer, index, len);
             index += len;
@@ -68,7 +68,7 @@ public class TiffImageWriterLossless extends 
TiffImageWriterBase {
         @Override
         public void write(final int b) throws IOException {
             if (index >= buffer.length) {
-                throw new IOException("Buffer overflow.");
+                throw new ImagingException("Buffer overflow.");
             }
 
             buffer[index++] = (byte) b;
diff --git a/src/main/java/org/apache/commons/imaging/icc/IccProfileParser.java 
b/src/main/java/org/apache/commons/imaging/icc/IccProfileParser.java
index 82af6b9c..07bf6b50 100644
--- a/src/main/java/org/apache/commons/imaging/icc/IccProfileParser.java
+++ b/src/main/java/org/apache/commons/imaging/icc/IccProfileParser.java
@@ -28,11 +28,13 @@ import java.nio.ByteOrder;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
+import org.apache.commons.imaging.ImagingException;
 import org.apache.commons.imaging.common.Allocator;
 import org.apache.commons.imaging.common.BinaryFileParser;
 import org.apache.commons.imaging.common.bytesource.ByteSource;
 import org.apache.commons.imaging.common.bytesource.ByteSourceArray;
 import org.apache.commons.imaging.common.bytesource.ByteSourceFile;
+import org.apache.commons.io.IOUtils;
 
 public class IccProfileParser extends BinaryFileParser {
 
@@ -138,7 +140,7 @@ public class IccProfileParser extends BinaryFileParser {
         return issRGB(new ByteSourceArray(iccProfile.getData()));
     }
 
-    private IccProfileInfo readICCProfileInfo(InputStream is) {
+    private IccProfileInfo readICCProfileInfo(InputStream is) throws 
IOException {
         final CachingInputStream cis = new CachingInputStream(is);
         is = cis;
 
@@ -147,159 +149,154 @@ public class IccProfileParser extends BinaryFileParser {
         // if (LOGGER.isLoggable(Level.FINEST))
         // Debug.debug("length: " + length);
 
-        try {
-            final int profileSize = read4Bytes("ProfileSize", is, "Not a Valid 
ICC Profile", getByteOrder());
-
-            // if (length != ProfileSize)
-            // {
-            // // Debug.debug("Unexpected Length data expected: " +
-            // Integer.toHexString((int) length)
-            // // + ", encoded: " + Integer.toHexString(ProfileSize));
-            // // Debug.debug("Unexpected Length data: " + length
-            // // + ", length: " + ProfileSize);
-            // // throw new Error("asd");
-            // return null;
-            // }
-
-            final int cmmTypeSignature = read4Bytes("Signature", is, "Not a 
Valid ICC Profile", getByteOrder());
-            if (LOGGER.isLoggable(Level.FINEST)) {
-                printCharQuad("CMMTypeSignature", cmmTypeSignature);
-            }
-
-            final int profileVersion = read4Bytes("ProfileVersion", is, "Not a 
Valid ICC Profile", getByteOrder());
-
-            final int profileDeviceClassSignature = 
read4Bytes("ProfileDeviceClassSignature", is,
-                    "Not a Valid ICC Profile", getByteOrder());
-            if (LOGGER.isLoggable(Level.FINEST)) {
-                printCharQuad("ProfileDeviceClassSignature", 
profileDeviceClassSignature);
-            }
+        final int profileSize = read4Bytes("ProfileSize", is, "Not a Valid ICC 
Profile", getByteOrder());
+
+        // if (length != ProfileSize)
+        // {
+        // // Debug.debug("Unexpected Length data expected: " +
+        // Integer.toHexString((int) length)
+        // // + ", encoded: " + Integer.toHexString(ProfileSize));
+        // // Debug.debug("Unexpected Length data: " + length
+        // // + ", length: " + ProfileSize);
+        // // throw new Error("asd");
+        // return null;
+        // }
+
+        final int cmmTypeSignature = read4Bytes("Signature", is, "Not a Valid 
ICC Profile", getByteOrder());
+        if (LOGGER.isLoggable(Level.FINEST)) {
+            printCharQuad("CMMTypeSignature", cmmTypeSignature);
+        }
 
-            final int colorSpace = read4Bytes("ColorSpace", is, "Not a Valid 
ICC Profile", getByteOrder());
-            if (LOGGER.isLoggable(Level.FINEST)) {
-                printCharQuad("ColorSpace", colorSpace);
-            }
+        final int profileVersion = read4Bytes("ProfileVersion", is, "Not a 
Valid ICC Profile", getByteOrder());
 
-            final int profileConnectionSpace = 
read4Bytes("ProfileConnectionSpace", is, "Not a Valid ICC Profile", 
getByteOrder());
-            if (LOGGER.isLoggable(Level.FINEST)) {
-                printCharQuad("ProfileConnectionSpace", 
profileConnectionSpace);
-            }
+        final int profileDeviceClassSignature = 
read4Bytes("ProfileDeviceClassSignature", is, "Not a Valid ICC Profile",
+                getByteOrder());
+        if (LOGGER.isLoggable(Level.FINEST)) {
+            printCharQuad("ProfileDeviceClassSignature", 
profileDeviceClassSignature);
+        }
 
-            skipBytes(is, 12, "Not a Valid ICC Profile");
+        final int colorSpace = read4Bytes("ColorSpace", is, "Not a Valid ICC 
Profile", getByteOrder());
+        if (LOGGER.isLoggable(Level.FINEST)) {
+            printCharQuad("ColorSpace", colorSpace);
+        }
 
-            final int profileFileSignature = 
read4Bytes("ProfileFileSignature", is, "Not a Valid ICC Profile", 
getByteOrder());
-            if (LOGGER.isLoggable(Level.FINEST)) {
-                printCharQuad("ProfileFileSignature", profileFileSignature);
-            }
+        final int profileConnectionSpace = 
read4Bytes("ProfileConnectionSpace", is, "Not a Valid ICC Profile",
+                getByteOrder());
+        if (LOGGER.isLoggable(Level.FINEST)) {
+            printCharQuad("ProfileConnectionSpace", profileConnectionSpace);
+        }
 
-            final int primaryPlatformSignature = 
read4Bytes("PrimaryPlatformSignature", is, "Not a Valid ICC Profile", 
getByteOrder());
-            if (LOGGER.isLoggable(Level.FINEST)) {
-                printCharQuad("PrimaryPlatformSignature", 
primaryPlatformSignature);
-            }
+        skipBytes(is, 12, "Not a Valid ICC Profile");
 
-            final int variousFlags = read4Bytes("VariousFlags", is, "Not a 
Valid ICC Profile", getByteOrder());
-            if (LOGGER.isLoggable(Level.FINEST)) {
-                printCharQuad("VariousFlags", profileFileSignature);
-            }
+        final int profileFileSignature = read4Bytes("ProfileFileSignature", 
is, "Not a Valid ICC Profile",
+                getByteOrder());
+        if (LOGGER.isLoggable(Level.FINEST)) {
+            printCharQuad("ProfileFileSignature", profileFileSignature);
+        }
 
-            final int deviceManufacturer = read4Bytes("DeviceManufacturer", 
is, "Not a Valid ICC Profile", getByteOrder());
-            if (LOGGER.isLoggable(Level.FINEST)) {
-                printCharQuad("DeviceManufacturer", deviceManufacturer);
-            }
+        final int primaryPlatformSignature = 
read4Bytes("PrimaryPlatformSignature", is, "Not a Valid ICC Profile",
+                getByteOrder());
+        if (LOGGER.isLoggable(Level.FINEST)) {
+            printCharQuad("PrimaryPlatformSignature", 
primaryPlatformSignature);
+        }
 
-            final int deviceModel = read4Bytes("DeviceModel", is, "Not a Valid 
ICC Profile", getByteOrder());
-            if (LOGGER.isLoggable(Level.FINEST)) {
-                printCharQuad("DeviceModel", deviceModel);
-            }
+        final int variousFlags = read4Bytes("VariousFlags", is, "Not a Valid 
ICC Profile", getByteOrder());
+        if (LOGGER.isLoggable(Level.FINEST)) {
+            printCharQuad("VariousFlags", profileFileSignature);
+        }
 
-            skipBytes(is, 8, "Not a Valid ICC Profile");
+        final int deviceManufacturer = read4Bytes("DeviceManufacturer", is, 
"Not a Valid ICC Profile", getByteOrder());
+        if (LOGGER.isLoggable(Level.FINEST)) {
+            printCharQuad("DeviceManufacturer", deviceManufacturer);
+        }
 
-            final int renderingIntent = read4Bytes("RenderingIntent", is, "Not 
a Valid ICC Profile", getByteOrder());
-            if (LOGGER.isLoggable(Level.FINEST)) {
-                printCharQuad("RenderingIntent", renderingIntent);
-            }
+        final int deviceModel = read4Bytes("DeviceModel", is, "Not a Valid ICC 
Profile", getByteOrder());
+        if (LOGGER.isLoggable(Level.FINEST)) {
+            printCharQuad("DeviceModel", deviceModel);
+        }
 
-            skipBytes(is, 12, "Not a Valid ICC Profile");
+        skipBytes(is, 8, "Not a Valid ICC Profile");
 
-            final int profileCreatorSignature = 
read4Bytes("ProfileCreatorSignature", is, "Not a Valid ICC Profile", 
getByteOrder());
-            if (LOGGER.isLoggable(Level.FINEST)) {
-                printCharQuad("ProfileCreatorSignature", 
profileCreatorSignature);
-            }
+        final int renderingIntent = read4Bytes("RenderingIntent", is, "Not a 
Valid ICC Profile", getByteOrder());
+        if (LOGGER.isLoggable(Level.FINEST)) {
+            printCharQuad("RenderingIntent", renderingIntent);
+        }
 
-            skipBytes(is, 16, "Not a Valid ICC Profile");
-            // readByteArray("ProfileID", 16, is,
-            // "Not a Valid ICC Profile");
-            // if (LOGGER.isLoggable(Level.FINEST))
-            // System.out
-            // .println("ProfileID: '" + new String(ProfileID) + "'");
+        skipBytes(is, 12, "Not a Valid ICC Profile");
 
-            skipBytes(is, 28, "Not a Valid ICC Profile");
+        final int profileCreatorSignature = 
read4Bytes("ProfileCreatorSignature", is, "Not a Valid ICC Profile",
+                getByteOrder());
+        if (LOGGER.isLoggable(Level.FINEST)) {
+            printCharQuad("ProfileCreatorSignature", profileCreatorSignature);
+        }
 
-            // this.setDebug(true);
+        skipBytes(is, 16, "Not a Valid ICC Profile");
+        // readByteArray("ProfileID", 16, is,
+        // "Not a Valid ICC Profile");
+        // if (LOGGER.isLoggable(Level.FINEST))
+        // System.out
+        // .println("ProfileID: '" + new String(ProfileID) + "'");
 
-            final int tagCount = read4Bytes("TagCount", is, "Not a Valid ICC 
Profile", getByteOrder());
+        skipBytes(is, 28, "Not a Valid ICC Profile");
 
-            // List tags = new ArrayList();
-            final IccTag[] tags = Allocator.array(tagCount, IccTag[]::new, 40);
+        // this.setDebug(true);
 
-            for (int i = 0; i < tagCount; i++) {
-                final int tagSignature = read4Bytes("TagSignature[" + i + "]", 
is, "Not a Valid ICC Profile", getByteOrder());
-                // Debug.debug("TagSignature t "
-                // + Integer.toHexString(TagSignature));
+        final int tagCount = read4Bytes("TagCount", is, "Not a Valid ICC 
Profile", getByteOrder());
 
-                // this.printCharQuad("TagSignature", TagSignature);
-                final int offsetToData = read4Bytes("OffsetToData[" + i + "]", 
is, "Not a Valid ICC Profile", getByteOrder());
-                final int elementSize = read4Bytes("ElementSize[" + i + "]", 
is, "Not a Valid ICC Profile", getByteOrder());
+        // List tags = new ArrayList();
+        final IccTag[] tags = Allocator.array(tagCount, IccTag[]::new, 40);
 
-                final IccTagType fIccTagType = getIccTagType(tagSignature);
-                // if (fIccTagType == null)
-                // throw new Error("oops.");
+        for (int i = 0; i < tagCount; i++) {
+            final int tagSignature = read4Bytes("TagSignature[" + i + "]", is, 
"Not a Valid ICC Profile",
+                    getByteOrder());
+            // Debug.debug("TagSignature t "
+            // + Integer.toHexString(TagSignature));
 
-                // System.out
-                // .println("\t["
-                // + i
-                // + "]: "
-                // + ((fIccTagType == null)
-                // ? "unknown"
-                // : fIccTagType.name));
-                // Debug.debug();
+            // this.printCharQuad("TagSignature", TagSignature);
+            final int offsetToData = read4Bytes("OffsetToData[" + i + "]", is, 
"Not a Valid ICC Profile",
+                    getByteOrder());
+            final int elementSize = read4Bytes("ElementSize[" + i + "]", is, 
"Not a Valid ICC Profile", getByteOrder());
 
-                final IccTag tag = new IccTag(tagSignature, offsetToData,
-                        elementSize, fIccTagType);
-                // tag.dump("\t" + i + ": ");
-                tags[i] = tag;
-                // tags .add(tag);
-            }
+            final IccTagType fIccTagType = getIccTagType(tagSignature);
+            // if (fIccTagType == null)
+            // throw new Error("oops.");
 
-            {
-                // read stream to end, filling cache.
-                while (is.read() >= 0) { // NOPMD we're doing nothing with the 
data
-                }
-            }
+            // System.out
+            // .println("\t["
+            // + i
+            // + "]: "
+            // + ((fIccTagType == null)
+            // ? "unknown"
+            // : fIccTagType.name));
+            // Debug.debug();
+
+            final IccTag tag = new IccTag(tagSignature, offsetToData, 
elementSize, fIccTagType);
+            // tag.dump("\t" + i + ": ");
+            tags[i] = tag;
+            // tags .add(tag);
+        }
 
-            final byte[] data = cis.getCache();
+        {
+            // read stream to end, filling cache.
+            IOUtils.consume(is);
+        }
 
-            if (data.length < profileSize) {
-                throw new IOException("Couldn't read ICC Profile.");
-            }
+        final byte[] data = cis.getCache();
 
-            final IccProfileInfo result = new IccProfileInfo(data, profileSize,
-                    cmmTypeSignature, profileVersion,
-                    profileDeviceClassSignature, colorSpace,
-                    profileConnectionSpace, profileFileSignature,
-                    primaryPlatformSignature, variousFlags, deviceManufacturer,
-                    deviceModel, renderingIntent, profileCreatorSignature,
-                    null, tags);
+        if (data.length < profileSize) {
+            throw new ImagingException("Couldn't read ICC Profile.");
+        }
 
-            if (LOGGER.isLoggable(Level.FINEST)) {
-                LOGGER.finest("issRGB: " + result.issRGB());
-            }
+        final IccProfileInfo result = new IccProfileInfo(data, profileSize, 
cmmTypeSignature, profileVersion,
+                profileDeviceClassSignature, colorSpace, 
profileConnectionSpace, profileFileSignature,
+                primaryPlatformSignature, variousFlags, deviceManufacturer, 
deviceModel, renderingIntent,
+                profileCreatorSignature, null, tags);
 
-            return result;
-        } catch (final Exception e) {
-            LOGGER.log(Level.SEVERE, e.getMessage(), e);
+        if (LOGGER.isLoggable(Level.FINEST)) {
+            LOGGER.finest("issRGB: " + result.issRGB());
         }
 
-        return null;
+        return result;
     }
 
 }

Reply via email to