code: protected static BufferedImage loadImage (InputStream iis)
          throws IOException
      {
          BufferedImage image;
  
          if (iis instanceof ImageInputStream) {
              image = ImageIO.read(iis);
  
          } else {
              // if we don't already have an image input stream, create a memory cache image input
              // stream to avoid causing freakout if we're used in a sandbox because ImageIO
              // otherwise use FileCacheImageInputStream which tries to create a temp file
              MemoryCacheImageInputStream mciis = new MemoryCacheImageInputStream(iis);
              image = ImageIO.read(mciis);
              try {
                  // this doesn't close the underlying stream
                  mciis.close();
              } catch (IOException ioe) {
                  // ImageInputStreamImpl.close() throws an IOException if it's already closed;
                  // there's no way to find out if it's already closed or not, so we have to check
                  // the exception message to determine if this is actually warning worthy
                  if (!"closed".equals(ioe.getMessage())) {
                      log.warning("Failure closing image input '" + iis + "'.", ioe);
                  }
              }
          }
  
          // finally close our input stream
          StreamUtil.close(iis);
  
          return image;
      }
docs: Loads an image from the supplied input stream. Supports formats supported by {@link ImageIO}
  but not {@link FastImageIO}.