public static void writeImage(@NotNull BufferedImage image,
                                @NotNull OutputStream outputStream,
                                boolean lossless,
                                int quality) throws IOException {
    // Instead of
    //   ImageIO.write(image, WebpMetadata.WEBP_FORMAT_LOWER_CASE, stream);
    // which will pass null as the parameters to the ImageWriter, call through to the ImageWriter
    // more directly so we can set up the proper parameters:
    ImageTypeSpecifier type = ImageTypeSpecifier.createFromRenderedImage(image);
    Iterator<ImageWriter> iterator = ImageIO.getImageWriters(type, WebpMetadata.WEBP_FORMAT_LOWER_CASE);
    if (iterator.hasNext()) {
      ImageWriter writer = iterator.next();
      try (ImageOutputStream stream = ImageIO.createImageOutputStream(outputStream)) {
        writer.setOutput(stream);
        try {
          ImageWriteParam param = new WebpImageWriteParam(writer.getLocale(), !lossless, quality / 100f);
          writer.write(null, new IIOImage(image, null, null), param);
        }
        finally {
          writer.dispose();
          stream.flush();
        }
      }
    }
  }
public static void writeImage(@NotNull BufferedImage image,
                                @NotNull OutputStream outputStream,
                                boolean lossless,
                                int quality)