JpegToPngRenditionProvider implements RenditionProvider { @Override public InputStream convert(InputStream fromInputSource, String toMimeType) { try { File tmpFile = Files.createTempFile(null, null, new FileAttribute<?>[]{}).toFile(); BufferedImage bufferedImage = ImageIO.read(fromInputSource); ImageIO.write(bufferedImage, "png", tmpFile); return new ObservableInputStream(new FileInputStream(tmpFile), new FileRemover(tmpFile)); } catch (Exception e) { logger.warn(format("%s rendition failed", toMimeType), e); } finally { IOUtils.closeQuietly(fromInputSource); } return null; }  @Override String consumes(); @Override String[] produces(); @Override InputStream convert(InputStream fromInputSource, String toMimeType);  }
@Test public void testConvert() throws Exception { InputStream converted = service.convert(this.getClass().getResourceAsStream("/sample.jpeg"), "image/png"); assertThat(converted.available(), is(greaterThan(0))); assertThat(((ObservableInputStream)converted).getObservers(), hasItem(is(instanceOf(FileRemover.class)))); assertThat(IOUtils.contentEquals(converted, this.getClass().getResourceAsStream("/sample.png")), is(true)); }