I'm reading images from various URLs. And some of them became a very interesting problem.
The full error: javax.imageio.IIOException: Invalid icc profile: invalid number of icc markers
Some code, but I'm sure it won't help much:
URLConnection wat = new URL(strurl).openConnection();
wat.setRequestProperty("User-Agent", userAgent);
InputStream in = null;
try {
in = wat.getInputStream();
} catch(FileNotFoundException e) {
e.printStackTrace();
Logger.getLogger().logException(e);
}
if(in == null) continue;
ByteArrayOutputStream outArray = new ByteArrayOutputStream();
byte[] bytes = new byte[50000];
int bytesRead;
while((bytesRead = in.read(bytes, 0, bytes.length)) > 0) {
outArray.write(bytes, 0, bytesRead);
bytesRead = 0;
}
in.close();
String format = getFileFormat(outArray.toByteArray());
in = new ByteArrayInputStream(outArray.toByteArray());
BufferedImage image = null;
try {
image = ImageIO.read(in);
} catch(IOException e) {
e.printStackTrace();
Logger.getLogger().logException(e);
}
I read the bytes first to determine what file type is it.
This is the photo which seems to cause this exception to be thrown: http://www.loupiote.com/photos_l/3215396684-khmer-goddess-stone-statue-wat-phu-champasak-laos.jpg
Weirdly I couldn't find any information about this error.
EDIT: this is not actually a sollution, but because I was saving those files I stopped constructing a BufferedImage
and just "dumped" those bytes to a file.