code: public static BufferedImage readClipped(final ImageInputStream stream) throws IOException {
          Shape clip = readPath(stream);
  
          stream.seek(0);
          BufferedImage image = ImageIO.read(stream);
  
          if (clip == null) {
              return image;
          }
  
          return applyClippingPath(clip, image);
      }
docs: Reads the clipping path from the given input stream, if any,
  and applies it to the first image in the stream.
  If no path was found, the image is returned without any clipping.
  Supports PSD, JPEG and TIFF as container formats for Photoshop resources.
  
  @param stream the stream to read from, not {@code null}
  @return the clipped image
  
  @throws IOException if a general I/O exception occurs during reading.
  @throws javax.imageio.IIOException if the input contains a bad image or path data.
  @throws java.lang.IllegalArgumentException is {@code stream} is {@code null}.