public void processImage(String fileName) throws IOException {
   if (fileName.startsWith("/")) {
     throw new IllegalArgumentException();
   }
   final SourceStringReader sourceStringReader = new SourceStringReader(incoming.get(fileName));
   final ByteArrayOutputStream baos = new ByteArrayOutputStream();
   final FileFormat format = FileFormat.PNG;
   final DiagramDescription desc =
       sourceStringReader.generateDiagramDescription(baos, new FileFormatOption(format));
   final String pngFileName = format.changeName(fileName, 0);
   final String errorFileName = pngFileName.substring(0, pngFileName.length() - 4) + ".err";
   synchronized (this) {
     outgoing.remove(pngFileName);
     outgoing.remove(errorFileName);
     if (desc != null && desc.getDescription() != null) {
       outgoing.put(pngFileName, baos.toByteArray());
       if (desc.getDescription().startsWith("(Error)")) {
         final ByteArrayOutputStream errBaos = new ByteArrayOutputStream();
         sourceStringReader.generateImage(errBaos, new FileFormatOption(FileFormat.ATXT));
         errBaos.close();
         outgoing.put(errorFileName, errBaos.toByteArray());
       }
     }
   }
 }
  @Override
  public MyDoc process(MyDoc madoc) throws IOException {

    // SVG
    SourceStringReader reader = new SourceStringReader(madoc.getCode());
    final ByteArrayOutputStream os = new ByteArrayOutputStream();
    // Write the first image to "os"
    reader.generateImage(os, new FileFormatOption(FileFormat.SVG));
    os.close();
    // The XML is stored into svg
    String svg = new String(os.toByteArray());
    svg = svg.replaceAll(XML_HEADER, "");
    madoc.setResult(svg);
    return madoc;
  }
  public static void createImageFileSvg(String filePathName, String textDiagram) {
    FileOutputStream fos = null;

    try {
      fos = new FileOutputStream(filePathName);
      SourceStringReader reader = new SourceStringReader(textDiagram);
      reader.generateImage(fos, new FileFormatOption(FileFormat.SVG));
    } catch (IOException e) {
      WorkbenchUtil.errorBox("Error during file generation for printing.");
    } finally {
      if (fos != null) {
        try {
          fos.close();
        } catch (IOException e) {
          WorkbenchUtil.errorBox("Error during file generation.");
        }
      }
    }
  }