protected Image standardImageBytesToImage(byte[] bytes,String mimeType) throws IOException {
  Iterator readerIterator=ImageIO.getImageReadersByMIMEType(mimeType);
  if (!readerIterator.hasNext()) {
    throw new IOException("No registered service provider can decode " + " an image from " + mimeType);
  }
  IOException ioe=null;
  while (readerIterator.hasNext()) {
    ImageReader imageReader=(ImageReader)readerIterator.next();
    try (ByteArrayInputStream bais=new ByteArrayInputStream(bytes)){
      ImageInputStream imageInputStream=ImageIO.createImageInputStream(bais);
      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;
    }
  }
  if (ioe == null) {
    ioe=new IOException("Registered service providers failed to decode" + " an image from " + mimeType);
  }
  throw ioe;
}

protected Image standardImageBytesToImage ( byte [ ] bytes , String mimeType ) throws IOException { Iterator readerIterator = ImageIO . getImageReadersByMIMEType ( mimeType ) ; if ( ! readerIterator . hasNext ( ) ) { throw new IOException ( "No registered service provider can decode " + " an image from " + mimeType ) ; } IOException ioe = null ; while ( readerIterator . hasNext ( ) ) { ImageReader imageReader = ( ImageReader ) readerIterator . next ( ) ; try ( ByteArrayInputStream bais = new ByteArrayInputStream ( bytes ) ) { ImageInputStream imageInputStream = ImageIO . createImageInputStream ( bais ) ; 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 ; } } if ( ioe == null ) { ioe = new IOException ( "Registered service providers failed to decode" + " an image from " + mimeType ) ; } throw ioe ; }
translates either a byte array or an input stream which contain an image data in the given standard format into an image .
