Class SAXReaderUtil


  • public final class SAXReaderUtil
    extends Object
    A utility class that provides a level of abstraction around the creation of a SAXReader instance suitable for XMPP parsing, as well as maintaining a set of readers ready, available for (bulk) processing.
    Author:
    Guus der Kinderen, guus.der.kinderen@gmail.com
    • Field Detail

      • PARSER_SERVICE_CORE_POOL_SIZE

        public static final SystemProperty<Integer> PARSER_SERVICE_CORE_POOL_SIZE
        The number of threads to keep in the SAX Reader pool, even if they are idle.
      • PARSER_SERVICE_MAX_POOL_SIZE

        public static final SystemProperty<Integer> PARSER_SERVICE_MAX_POOL_SIZE
        The maximum number of threads to allow in the SAX Reader pool.
      • PARSER_SERVICE_KEEP_ALIVE_TIME

        public static final SystemProperty<Duration> PARSER_SERVICE_KEEP_ALIVE_TIME
        When the number of threads in the SAX reader pool is greater than the core, this is the maximum time that excess idle threads will wait for new tasks before terminating.
    • Constructor Detail

      • SAXReaderUtil

        public SAXReaderUtil()
    • Method Detail

      • readDocumentAsync

        public static Future<org.dom4j.Document> readDocumentAsync​(@Nonnull
                                                                   InputStream stream)
        Schedules parsing of the provided input stream into an XML Document as an asynchronous process. This method returns a Future object that can be used to obtain the result of the asynchronous process. The XML parsing is delegated to a limited set of parsers, that is fronted by an Executor Service. The amount of parsers that are available is equal to the amount of threads available in the Executor Service. This can be optimized by using the SystemProperties in this class.
        Parameters:
        stream - The data to be parsed as an XML Document.
        Returns:
        A Future representing pending completion of parsing the provided data as an XML Document.
      • readDocument

        public static org.dom4j.Document readDocument​(@Nonnull
                                                      InputStream stream)
                                               throws ExecutionException,
                                                      InterruptedException
        Parses an XML Document from the content provided by an input stream. Equivalent to calling readDocumentAsync(input).get() The XML parsing is delegated to a limited set of parsers, as documented in readDocumentAsync(InputStream). When a parser is not immediately available, this method will block until one becomes available.
        Parameters:
        stream - The data to be parsed as an XML Document.
        Returns:
        an XML Document.
        Throws:
        ExecutionException - on any error that occurs during parsing (this typically has a DocumentException as its cause).
        InterruptedException - when the task that is scheduled to perform the parsing gets interrupted during the execution of the task.
      • readRootElement

        public static org.dom4j.Element readRootElement​(@Nonnull
                                                        InputStream stream)
                                                 throws ExecutionException,
                                                        InterruptedException
        Parses an XML Document from the content provided by an input stream and returns the root element of the document. Equivalent to calling readDocument(input).getRootElement()
        Parameters:
        stream - The data to be parsed as an XML Document.
        Returns:
        an XML Document root element.
        Throws:
        ExecutionException - on any error that occurs during parsing (this typically has a DocumentException as its cause).
        InterruptedException - when the task that is scheduled to perform the parsing gets interrupted during the execution of the task.
      • readDocumentAsync

        public static Future<org.dom4j.Document> readDocumentAsync​(@Nonnull
                                                                   String text)
        Schedules parsing of the provided text into an XML Document as an asynchronous process. This method returns a Future object that can be used to obtain the result of the asynchronous process. The XML parsing is delegated to a limited set of parsers, that is fronted by an Executor Service. The amount of parsers that are available is equal to the amount of threads available in the Executor Service. This can be optimized by using the SystemProperties in this class.
        Parameters:
        text - The data to be parsed as an XML Document.
        Returns:
        A Future representing pending completion of parsing the provided data as an XML Document.
      • readDocument

        public static org.dom4j.Document readDocument​(@Nonnull
                                                      String text)
                                               throws ExecutionException,
                                                      InterruptedException
        Parses an XML Document from the provided text. Equivalent to calling readDocumentAsync(input).get() The XML parsing is delegated to a limited set of parsers, as documented in readDocumentAsync(String). When a parser is not immediately available, this method will block until one becomes available.
        Parameters:
        text - The data to be parsed as an XML Document.
        Returns:
        an XML Document.
        Throws:
        ExecutionException - on any error that occurs during parsing (this typically has a DocumentException as its cause).
        InterruptedException - when the task that is scheduled to perform the parsing gets interrupted during the execution of the task.
      • readRootElement

        public static org.dom4j.Element readRootElement​(@Nonnull
                                                        String text)
                                                 throws ExecutionException,
                                                        InterruptedException
        Parses an XML Document from the provided text and returns the root element of the document. Equivalent to calling readDocument(input).getRootElement()
        Parameters:
        text - The data to be parsed as an XML Document.
        Returns:
        an XML Document root element.
        Throws:
        ExecutionException - on any error that occurs during parsing (this typically has a DocumentException as its cause).
        InterruptedException - when the task that is scheduled to perform the parsing gets interrupted during the execution of the task.
      • readDocumentAsync

        public static Future<org.dom4j.Document> readDocumentAsync​(@Nonnull
                                                                   Reader reader)
        Schedules parsing of the provided reader into an XML Document as an asynchronous process. This method returns a Future object that can be used to obtain the result of the asynchronous process. The XML parsing is delegated to a limited set of parsers, that is fronted by an Executor Service. The amount of parsers that are available is equal to the amount of threads available in the Executor Service. This can be optimized by using the SystemProperties in this class.
        Parameters:
        reader - The data to be parsed as an XML Document.
        Returns:
        A Future representing pending completion of parsing the provided data as an XML Document.
      • readDocument

        public static org.dom4j.Document readDocument​(@Nonnull
                                                      Reader reader)
                                               throws ExecutionException,
                                                      InterruptedException
        Parses an XML Document from the content provided by a reader. Equivalent to calling readDocumentAsync(input).get() The XML parsing is delegated to a limited set of parsers, as documented in readDocumentAsync(Reader). When a parser is not immediately available, this method will block until one becomes available.
        Parameters:
        reader - The data to be parsed as an XML Document.
        Returns:
        an XML Document.
        Throws:
        ExecutionException - on any error that occurs during parsing (this typically has a DocumentException as its cause).
        InterruptedException - when the task that is scheduled to perform the parsing gets interrupted during the execution of the task.
      • readRootElement

        public static org.dom4j.Element readRootElement​(@Nonnull
                                                        Reader reader)
                                                 throws ExecutionException,
                                                        InterruptedException
        Parses an XML Document from the content provided by a reader and returns the root element of the document. Equivalent to calling readDocument(input).getRootElement()
        Parameters:
        reader - The data to be parsed as an XML Document.
        Returns:
        an XML Document root element.
        Throws:
        ExecutionException - on any error that occurs during parsing (this typically has a DocumentException as its cause).
        InterruptedException - when the task that is scheduled to perform the parsing gets interrupted during the execution of the task.
      • readDocumentAsync

        public static Future<org.dom4j.Document> readDocumentAsync​(@Nonnull
                                                                   File file)
        Schedules parsing of content of afile into an XML Document as an asynchronous process. This method returns a Future object that can be used to obtain the result of the asynchronous process. The XML parsing is delegated to a limited set of parsers, that is fronted by an Executor Service. The amount of parsers that are available is equal to the amount of threads available in the Executor Service. This can be optimized by using the SystemProperties in this class.
        Parameters:
        file - The data to be parsed as an XML Document.
        Returns:
        A Future representing pending completion of parsing the provided data as an XML Document.
      • readDocument

        public static org.dom4j.Document readDocument​(@Nonnull
                                                      File file)
                                               throws ExecutionException,
                                                      InterruptedException
        Parses an XML Document from the content provided by a file. Equivalent to calling readDocumentAsync(input).get() The XML parsing is delegated to a limited set of parsers, as documented in readDocumentAsync(File). When a parser is not immediately available, this method will block until one becomes available.
        Parameters:
        file - The data to be parsed as an XML Document.
        Returns:
        an XML Document.
        Throws:
        ExecutionException - on any error that occurs during parsing (this typically has a DocumentException as its cause).
        InterruptedException - when the task that is scheduled to perform the parsing gets interrupted during the execution of the task.
      • readRootElement

        public static org.dom4j.Element readRootElement​(@Nonnull
                                                        File file)
                                                 throws ExecutionException,
                                                        InterruptedException
        Parses an XML Document from the content provided by a file and returns the root element of the document. Equivalent to calling readDocument(input).getRootElement()
        Parameters:
        file - The data to be parsed as an XML Document.
        Returns:
        an XML Document root element.
        Throws:
        ExecutionException - on any error that occurs during parsing (this typically has a DocumentException as its cause).
        InterruptedException - when the task that is scheduled to perform the parsing gets interrupted during the execution of the task.