Class AbstractImageSessionContext

  • All Implemented Interfaces:
    ImageSessionContext
    Direct Known Subclasses:
    DefaultImageSessionContext

    public abstract class AbstractImageSessionContext
    extends Object
    implements ImageSessionContext
    Abstract base class for classes implementing ImageSessionContext. This class provides all the special treatment for Source creation, i.e. it provides optimized Source objects where possible.
    • Constructor Detail

      • AbstractImageSessionContext

        public AbstractImageSessionContext()
    • Method Detail

      • resolveURI

        protected abstract Source resolveURI​(String uri)
        Attempts to resolve the given URI.
        Parameters:
        uri - URI to access
        Returns:
        A Source object, or null if the URI cannot be resolved.
      • newSource

        public Source newSource​(String uri)
        Attempts to create a Source object from the given URI. If possible this method returns an ImageSource instance which provides the best possible method to access the image.
        Specified by:
        newSource in interface ImageSessionContext
        Parameters:
        uri - URI to access
        Returns:
        A Source object, or null if the URI cannot be resolved.
      • toFile

        public static File toFile​(URL url)
        Convert from a URL to a File.

        This method will decode the URL. Syntax such as file:///my%20docs/file.txt will be correctly decoded to /my docs/file.txt.

        Note: this method has been copied over from Apache Commons IO and enhanced to support UNC paths.

        Parameters:
        url - the file URL to convert, null returns null
        Returns:
        the equivalent File object, or null if the URL's protocol is not file
        Throws:
        IllegalArgumentException - if the file is incorrectly encoded
      • getSource

        public Source getSource​(String uri)
        Returns a Source object for a URI. This method is not guaranteed to return an instance. Implementations normally return already created Sources from a pool (normally populated through the ImageSessionContext.returnSource(String, Source) method).
        Specified by:
        getSource in interface ImageSessionContext
        Parameters:
        uri - the URI of the image
        Returns:
        the Source object to load the image from, or null
      • returnSource

        public void returnSource​(String uri,
                                 Source src)
        Returns a Source object to a pool. This is provided in order to reuse a Source object between the preloading and the final loading of an image. Note that not all Source objects can be reused! Non-reusable Sources are discarded.
        Specified by:
        returnSource in interface ImageSessionContext
        Parameters:
        uri - the URI of the image
        src - the Source object belonging to the URI
      • isReusable

        protected boolean isReusable​(Source src)
        Indicates whether a Source is reusable. A Source object is reusable if it's an ImageSource (containing an ImageInputStream) or a DOMSource.
        Parameters:
        src - the Source object
        Returns:
        true if the Source is reusable