private synchronized void init() throws IOException { // Need the extra test, to avoid throwing an IOException from the Transcoder if (imageInput == null) { throw new IllegalStateException("input == null"); } if (reader == null) { WMFTranscoder transcoder = new WMFTranscoder(); ByteArrayOutputStream output = new ByteArrayOutputStream(); Writer writer = new OutputStreamWriter(output, "UTF8"); try { TranscoderInput in = new TranscoderInput(IIOUtil.createStreamAdapter(imageInput)); TranscoderOutput out = new TranscoderOutput(writer); // TODO: Transcodinghints? transcoder.transcode(in, out); } catch (TranscoderException e) { throw new IIOException(e.getMessage(), e); } reader = new SVGImageReader(getOriginatingProvider()); reader.setInput( ImageIO.createImageInputStream(new ByteArrayInputStream(output.toByteArray()))); } }
public TestReport encode(URL srcURL, FileOutputStream fos) { DefaultTestReport report = new DefaultTestReport(this); try { ImageTranscoder transcoder = getTestImageTranscoder(); TranscoderInput src = new TranscoderInput(svgURL.toString()); TranscoderOutput dst = new TranscoderOutput(fos); transcoder.transcode(src, dst); return null; } catch (TranscoderException e) { StringWriter trace = new StringWriter(); e.printStackTrace(new PrintWriter(trace)); report.setErrorCode(ERROR_CANNOT_TRANSCODE_SVG); report.setDescription( new TestReport.Entry[] { new TestReport.Entry( Messages.formatMessage(ENTRY_KEY_ERROR_DESCRIPTION, null), Messages.formatMessage( ERROR_CANNOT_TRANSCODE_SVG, new String[] { svgURL.toString(), e.getClass().getName(), e.getMessage(), trace.toString() })) }); } catch (Exception e) { StringWriter trace = new StringWriter(); e.printStackTrace(new PrintWriter(trace)); report.setErrorCode(ERROR_CANNOT_TRANSCODE_SVG); report.setDescription( new TestReport.Entry[] { new TestReport.Entry( Messages.formatMessage(ENTRY_KEY_ERROR_DESCRIPTION, null), Messages.formatMessage( ERROR_CANNOT_TRANSCODE_SVG, new String[] { svgURL.toString(), e.getClass().getName(), e.getMessage(), trace.toString() })) }); } report.setPassed(false); return report; }