IOException ioe = null;
while (readerIterator.hasNext()) {
ImageReader imageReader = (ImageReader)readerIterator.next();
try {
ImageInputStream imageInputStream =
ImageIO.createImageInputStream(inputStream);
try {
ImageReadParam param = imageReader.getDefaultReadParam();
imageReader.setInput(imageInputStream, true, true);
BufferedImage bufferedImage =
imageReader.read(imageReader.getMinIndex(), param);
if (bufferedImage != null) {
return bufferedImage;
}
} finally {
imageInputStream.close();
imageReader.dispose();
}
} catch (IOException e) {
ioe = e;
continue;