Class ExternalParser

  • All Implemented Interfaces:
    Serializable, Initializable, Parser

    public class ExternalParser
    extends Object
    implements Parser, Initializable
    This is a next generation external parser that uses some of the more recent additions to Tika. This is an experimental alternative to the ExternalParser. Specifically, it relies more on configuration than the SPI model. Further, users can specify a parser to handle the output of the external process.
    See Also:
    Serialized Form
    • Constructor Detail

      • ExternalParser

        public ExternalParser()
    • Method Detail

      • getSupportedTypes

        public Set<MediaType> getSupportedTypes​(ParseContext context)
        Description copied from interface: Parser
        Returns the set of media types supported by this parser when used with the given parse context.
        Specified by:
        getSupportedTypes in interface Parser
        Parameters:
        context - parse context
        Returns:
        immutable set of media types
      • parse

        public void parse​(InputStream stream,
                          ContentHandler handler,
                          Metadata metadata,
                          ParseContext context)
                   throws IOException,
                          SAXException,
                          TikaException
        Description copied from interface: Parser
        Parses a document stream into a sequence of XHTML SAX events. Fills in related document metadata in the given metadata object.

        The given document stream is consumed but not closed by this method. The responsibility to close the stream remains on the caller.

        Information about the parsing context can be passed in the context parameter. See the parser implementations for the kinds of context information they expect.

        Specified by:
        parse in interface Parser
        Parameters:
        stream - the document stream (input)
        handler - handler for the XHTML SAX events (output)
        metadata - document metadata (input and output)
        context - parse context
        Throws:
        IOException - if the document stream could not be read
        SAXException - if the SAX events could not be processed
        TikaException - if the document could not be parsed
      • setSupportedTypes

        @Field
        public void setSupportedTypes​(List<String> supportedTypes)
        This is set during initialization from a tika-config. Any calls after initialization will result in a IllegalStateException.
        Parameters:
        supportedTypes -
      • setTimeoutMs

        @Field
        public void setTimeoutMs​(long timeoutMs)
      • setMaxStdErr

        @Field
        public void setMaxStdErr​(int maxStdErr)
      • setMaxStdOut

        @Field
        public void setMaxStdOut​(int maxStdOut)
      • setCommandLine

        @Field
        public void setCommandLine​(List<String> commandLine)
        Use this to specify the full commandLine. The commandline must include at least INPUT_FILE_TOKEN. If the external process writes to an output file, specify OUTPUT_FILE_TOKEN.
        Parameters:
        commandLine -
      • setReturnStdout

        @Field
        public void setReturnStdout​(boolean returnStdout)
        If set to true, this will return the stdout in the metadata via ExternalProcess.STD_OUT. Default is false because this should normally be handled by the outputParser
        Parameters:
        returnStdout -
      • setReturnStderr

        @Field
        public void setReturnStderr​(boolean returnStderr)
        If set to true, this will return the stderr in the metadata via ExternalProcess.STD_ERR. Default is true
        Parameters:
        returnStderr -
      • setOutputParser

        @Field
        public void setOutputParser​(Parser parser)
        This parser is called on the output of the process. If the process writes to an output file, specified by OUTPUT_FILE_TOKEN, this parser will parse that file, otherwise it will parse the UTF-8 encoded bytes from the process' STD_OUT.
        Parameters:
        parser -
      • getOutputParser

        public Parser getOutputParser()