code: private synchronized Image loadImage(InputStream stream) throws IOException {
          Toolkit toolkit = Toolkit.getDefaultToolkit();
          byte data[] = FileCopyUtils.copyToByteArray(stream);
  
          Image image = toolkit.createImage(data);
          imageLoaded = false;
          imageError = false;
          // fully loads the image into memory
          toolkit.prepareImage(image, -1, -1, this);
          while (!imageLoaded && !imageError) {
              try {
                  wait();
              }
              catch (InterruptedException ex) {
              }
          }
          if (imageError) {
              throw new IOException("Error preparing image from resource.");
          }
          return image;
      }
docs: Load an image from the underlying resource's input stream. Constructs a
  new <code>Image</code> object from the data read from the input stream
  on each call.
  <p>
  This method loads the image fully into memory. This improves UI
  responsiveness when the image is needed by the GUI event-dispatching
  thread.
  
  @param stream
  The input stream.
  @return The resulting <code>Image</code> object.
  @throws java.io.IOException
  If an error occurred while reading from the stream.