if (type != null) {
try {
Iterator<ImageReader> iterator =
ImageIO.getImageReadersByMIMEType(type);
if (iterator.hasNext()) {
ImageReader reader = iterator.next();
reader.setInput(ImageIO.createImageInputStream(
new CloseShieldInputStream(stream)));
metadata.set(Metadata.IMAGE_WIDTH, Integer.toString(reader.getWidth(0)));
metadata.set(Metadata.IMAGE_LENGTH, Integer.toString(reader.getHeight(0)));
metadata.set("height", Integer.toString(reader.getHeight(0)));
metadata.set("width", Integer.toString(reader.getWidth(0)));
loadMetadata(reader.getImageMetadata(0), metadata);
reader.dispose();
}
// Translate certain Metadata tags from the ImageIO
// specific namespace into the general Tika one
setIfPresent(metadata, "CommentExtensions CommentExtension", Metadata.COMMENTS);