Class MemoryURLConnectionFactory

All Implemented Interfaces:

public class MemoryURLConnectionFactory extends Object implements URLConnectionFactory
A general purpose URLConnectionFactory which can be used to map particular URLs to a preloaded byte array, known as a "Blob" (after the same term in web browsers).

An instance of this can be used to override any URL - it can be added to the ReportFactory or a single Report#getURLConnectionFactories by calling the getURLConnectionFactories() method on either class. If it is to override URLs that would be handled normally, eg "http" or "file" URLs, it should be put at the start of the list to ensure it has the highest-priority.

  MemoryURLConnectionFactory factory = new MemoryURLConnectionFactory();
  Map<URL2,AbstractBlob> map = factory.getMap();
  ByteBuffer data = ...;       // your data, from any source
  URL2 url = URL2.parse("");
  Blob blob = new Blob(url, MediaType.parse("text/html"), data, 0);
  map.put(blob.getURL(), blob);

  Report report = reportfactory.createReport();
  report.getURLConnectionFactories().add(0, myhandler);
  • Constructor Details

    • MemoryURLConnectionFactory

      public MemoryURLConnectionFactory()
      Create a new MemoryURLConnectionFactory
    • MemoryURLConnectionFactory

      public MemoryURLConnectionFactory(Map<? extends URL2,? extends AbstractBlob> m)
      Create a new MemoryURLConnectionFactory. The supplied map will be copied to the map returned by getMap()
      map - the map to copy to the internal map.
  • Method Details

    • getURLConnection

      public URL2Connection getURLConnection(URL2 uri, ReportFactory reportFactory) throws IOException
      Description copied from interface: URLConnectionFactory
      Return a URLConnection for the specified URI, or null if not possible with this factory.
      Specified by:
      getURLConnection in interface URLConnectionFactory
      uri - the URI
      reportFactory - the ReportFactory that owns this connection
    • supports

      public boolean supports(URL2 url)
      Return true if this URLConnectionFactory supports the specified URL. This returns true if the URL is a key in the map returned by getMap()
      Specified by:
      supports in interface URLConnectionFactory
      url - the URL
    • getMap

      public Map<URL2,AbstractBlob> getMap()
      Return the Map of URLs to {link AbstractBlob} values. The returned map can be edited in thread-safe way without synchronization, and all keys and values must be non0null.