ImageInputStream in = ImageIO.createImageInputStream(entityStream);
reader.setInput(in, true, true);
BufferedImage bi = reader.read(0, reader.getDefaultReadParam());
in.close();
reader.dispose();
return bi;
} else {
return ImageIO.read(entityStream);
}
}