Class ImageCacher

java.lang.Object
org.apache.batik.svggen.ImageCacher
All Implemented Interfaces:
XMLConstants, ErrorConstants, SVGSyntax, CSSConstants, SVGConstants
Direct Known Subclasses:
ImageCacher.Embedded, ImageCacher.External

public abstract class ImageCacher extends Object implements SVGSyntax, ErrorConstants
This class implements caching functionality for raster images.
Version:
$Id: ImageCacher.java 1802297 2017-07-18 13:58:12Z ssteiner $
  • Field Details

  • Constructor Details

    • ImageCacher

      public ImageCacher()
      Creates an ImageCacher.
    • ImageCacher

      public ImageCacher(DOMTreeManager domTreeManager)
      Creates an ImageCacher.
      Parameters:
      domTreeManager - the DOMTreeManager for the tree this cacher works on
  • Method Details

    • setDOMTreeManager

      public void setDOMTreeManager(DOMTreeManager domTreeManager)
      Sets the DOMTreeManager this cacher should work on.
      Parameters:
      domTreeManager - the DOMTreeManager for the tree this cacher works on
    • getDOMTreeManager

      public DOMTreeManager getDOMTreeManager()
    • lookup

      public String lookup(ByteArrayOutputStream os, int width, int height, SVGGeneratorContext ctx) throws SVGGraphics2DIOException
      Checks if the image is already in the cache, and adds it if not. Returns a unique id for the entry.
      Parameters:
      os - the image as a byte stream
      width - the width of the image
      height - the height of the image
      ctx - the SVGGeneratorContext
      Returns:
      a URI for the image
      Throws:
      SVGGraphics2DIOException - if an error occurs during image file i/o
    • getCacheableData

      abstract Object getCacheableData(ByteArrayOutputStream os)
      Returns an object which can be cached. Implementation must determine which information should actually be stored.
      Parameters:
      os - the byte stream which is to be coerced
    • imagesMatch

      abstract boolean imagesMatch(Object o1, Object o2) throws SVGGraphics2DIOException
      Determines if two images are equal. Interpretation of the objects referred to by o1 and o2 is entirely implementation-dependent.
      Parameters:
      o1 - object referring to one image
      o2 - object referring to the other image
      Throws:
      SVGGraphics2DIOException
    • createEntry

      abstract ImageCacher.ImageCacheEntry createEntry(int checksum, Object data, int width, int height, SVGGeneratorContext ctx) throws SVGGraphics2DIOException
      Creates a new entry for keeping in the cache.
      Parameters:
      checksum - the checksum from which the hash key is derived
      data - the data to be cached
      width - image width
      height - image height
      ctx - the SVGGeneratorContext
      Throws:
      SVGGraphics2DIOException
    • getChecksum

      int getChecksum(byte[] data)
      Calculates a checksum value for the given data.