Class AbstractXmlParser.CachedFileEntityResolver

  • All Implemented Interfaces:
    org.xml.sax.EntityResolver
    Enclosing class:
    AbstractXmlParser

    public static class AbstractXmlParser.CachedFileEntityResolver
    extends java.lang.Object
    implements org.xml.sax.EntityResolver
    Implementation of the callback mechanism EntityResolver. Using a mechanism of cached files in temp dir to improve performance when using the XMLReader.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected static java.util.Map<java.lang.String,​byte[]> ENTITY_CACHE
      Map with systemId as key and the content of systemId as byte[].
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private void copy​(byte[] res, java.io.File f)
      Wrap IOUtil.copy(byte[], OutputStream) to throw SAXException.
      org.xml.sax.InputSource resolveEntity​(java.lang.String publicId, java.lang.String systemId)
      private static byte[] toByteArray​(java.net.URL url)
      If url is not an http/https urls, call IOUtil.toByteArray(java.io.InputStream) to get the url content.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • ENTITY_CACHE

        protected static final java.util.Map<java.lang.String,​byte[]> ENTITY_CACHE
        Map with systemId as key and the content of systemId as byte[].
    • Constructor Detail

      • CachedFileEntityResolver

        public CachedFileEntityResolver()
    • Method Detail

      • resolveEntity

        public org.xml.sax.InputSource resolveEntity​(java.lang.String publicId,
                                                     java.lang.String systemId)
                                              throws org.xml.sax.SAXException,
                                                     java.io.IOException
        Specified by:
        resolveEntity in interface org.xml.sax.EntityResolver
        Throws:
        org.xml.sax.SAXException
        java.io.IOException
      • toByteArray

        private static byte[] toByteArray​(java.net.URL url)
                                   throws org.xml.sax.SAXException
        If url is not an http/https urls, call IOUtil.toByteArray(java.io.InputStream) to get the url content. Otherwise, use HttpClient to get the http content. Wrap all internal exceptions to throw SAXException.
        Parameters:
        url - not null
        Returns:
        return an array of byte
        Throws:
        org.xml.sax.SAXException - if any
      • copy

        private void copy​(byte[] res,
                          java.io.File f)
                   throws org.xml.sax.SAXException
        Wrap IOUtil.copy(byte[], OutputStream) to throw SAXException.
        Parameters:
        res - not null array of byte
        f - the file where to write the bytes
        Throws:
        org.xml.sax.SAXException - if any
        See Also:
        IOUtil.copy(byte[], OutputStream)