protected void cacheBufferedImage(
      Element imageElement, BufferedImage buf, SVGGeneratorContext generatorContext)
      throws SVGGraphics2DIOException {

    ByteArrayOutputStream os;

    if (generatorContext == null) throw new SVGGraphics2DRuntimeException(ERR_CONTEXT_NULL);

    try {
      os = new ByteArrayOutputStream();
      // encode the image in memory
      encodeImage(buf, os);
      os.flush();
      os.close();
    } catch (IOException e) {
      // should not happen since we do in-memory processing
      throw new SVGGraphics2DIOException(ERR_UNEXPECTED, e);
    }

    // ask the cacher for a reference
    String ref = imageCacher.lookup(os, buf.getWidth(), buf.getHeight(), generatorContext);

    // set the URL
    imageElement.setAttributeNS(XLINK_NAMESPACE_URI, XLINK_HREF_QNAME, getRefPrefix() + ref);
  }
 /**
  * This <code>GenericImageHandler</code> implementation does not need to interact with the
  * DOMTreeManager.
  */
 public void setDOMTreeManager(DOMTreeManager domTreeManager) {
   imageCacher.setDOMTreeManager(domTreeManager);
 }