### Question:
WebPWriter extends ImageWriter { @Override public void write( IIOMetadata streamMetadata, IIOImage image, ImageWriteParam param ) throws IOException { if ( param == null ) { param = getDefaultWriteParam(); } WebPWriteParam writeParam = (WebPWriteParam) param; ImageOutputStream output = ( ImageOutputStream ) getOutput(); RenderedImage ri = image.getRenderedImage(); byte[] encodedData = WebP.encode(writeParam, ri); output.write( encodedData ); } WebPWriter( ImageWriterSpi originatingProvider ); @Override ImageWriteParam getDefaultWriteParam(); @Override IIOMetadata convertImageMetadata( IIOMetadata inData, ImageTypeSpecifier imageType, ImageWriteParam param ); @Override IIOMetadata convertStreamMetadata( IIOMetadata inData, ImageWriteParam param ); @Override IIOMetadata getDefaultImageMetadata( ImageTypeSpecifier imageType, ImageWriteParam param ); @Override IIOMetadata getDefaultStreamMetadata( ImageWriteParam param ); @Override void write( IIOMetadata streamMetadata, IIOImage image, ImageWriteParam param );  }### Answer:
@Test(dataProvider = "createBasicImages", enabled = true) public void testImageIoWrite(final RenderedImage im, final String outputName) throws IOException { final ByteArrayOutputStream baoStream = new ByteArrayOutputStream(); ImageIO.write(im, "webp", baoStream); assertTrue(baoStream.size() > 0); final String testName = "ImageIo"; final File file = createOutputFile(testName, outputName); final FileOutputStream foStream = new FileOutputStream(file); baoStream.writeTo(foStream); foStream.close(); }
@Test(dataProvider = "createImagesWithCompressionOptions", enabled = true) public void testImageWriterCompression(final RenderedImage im, final String compressionType, final float compressionQuality, final String outputName) throws IOException { final String extension = outputName.substring(outputName.lastIndexOf(".") + 1); final ImageWriter imgWriter = ImageIO.getImageWritersByFormatName(extension).next(); final ImageWriteParam imgWriteParams = new WebPWriteParam(null); imgWriteParams.setCompressionType(compressionType); imgWriteParams.setCompressionQuality(compressionQuality); final String testName = "CompressionOptions"; final File file = createOutputFile(testName, outputName); final ImageOutputStream imageOutputStream = ImageIO.createImageOutputStream(file); try { imgWriter.setOutput(imageOutputStream); imgWriter.write(null, new IIOImage(im, null, null), imgWriteParams); final int length = (int) imageOutputStream.length(); assertTrue(length > 0); } finally { try { imageOutputStream.close(); } catch (final IOException e) { } } }
@Test(dataProvider = "createImagesWithScaleOptions", enabled = true) public void testImageWriterScale(final RenderedImage image, final float xScale, final float yScale, final String outputName) throws IOException { final String extension = outputName.substring(outputName.lastIndexOf(".") + 1); final RenderedOp scaledImage = ScaleDescriptor.create(image, xScale, yScale, 0f, 0f, Interpolation.getInstance(Interpolation.INTERP_BICUBIC_2), null); final ImageWriter imgWriter = ImageIO.getImageWritersByFormatName(extension).next(); final ImageWriteParam imgWriteParams = new WebPWriteParam(null); final String testName = "ScaleOptions"; final File file = createOutputFile(testName, outputName); final ImageOutputStream imageOutputStream = ImageIO.createImageOutputStream(file); try { imgWriter.setOutput(imageOutputStream); imgWriter.write(null, new IIOImage(scaledImage, null, null), imgWriteParams); final int length = (int) imageOutputStream.length(); assertTrue(length > 0); } finally { try { imageOutputStream.close(); } catch (final IOException e) { } } }