Package org.apache.tika.parser.external2
Class ExternalParser
java.lang.Object
org.apache.tika.parser.external2.ExternalParser
- All Implemented Interfaces:
Serializable
,Initializable
,Parser
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:
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
checkInitialization
(InitializableProblemHandler problemHandler) getSupportedTypes
(ParseContext context) Returns the set of media types supported by this parser when used with the given parse context.void
initialize
(Map<String, Param> params) void
parse
(InputStream stream, ContentHandler handler, Metadata metadata, ParseContext context) Parses a document stream into a sequence of XHTML SAX events.void
setCommandLine
(List<String> commandLine) Use this to specify the full commandLine.void
setMaxStdErr
(int maxStdErr) void
setMaxStdOut
(int maxStdOut) void
setOutputParser
(Parser parser) This parser is called on the output of the process.void
setReturnStderr
(boolean returnStderr) If set to true, this will return the stderr in the metadata viaExternalProcess.STD_ERR
.void
setReturnStdout
(boolean returnStdout) If set to true, this will return the stdout in the metadata viaExternalProcess.STD_OUT
.void
setSupportedTypes
(List<String> supportedTypes) This is set during initialization from a tika-config.void
setTimeoutMs
(long timeoutMs)
-
Field Details
-
DEFAULT_TIMEOUT_MS
public static final long DEFAULT_TIMEOUT_MS- See Also:
-
INPUT_FILE_TOKEN
- See Also:
-
OUTPUT_FILE_TOKEN
- See Also:
-
-
Constructor Details
-
ExternalParser
public ExternalParser()
-
-
Method Details
-
getSupportedTypes
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 interfaceParser
- 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 interfaceParser
- 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 readSAXException
- if the SAX events could not be processedTikaException
- if the document could not be parsed
-
setSupportedTypes
This is set during initialization from a tika-config. Any calls after initialization will result in aIllegalStateException
.- Parameters:
supportedTypes
-
-
setTimeoutMs
-
setMaxStdErr
-
setMaxStdOut
-
setCommandLine
Use this to specify the full commandLine. The commandline must include at leastINPUT_FILE_TOKEN
. If the external process writes to an output file, specifyOUTPUT_FILE_TOKEN
.- Parameters:
commandLine
-
-
setReturnStdout
If set to true, this will return the stdout in the metadata viaExternalProcess.STD_OUT
. Default isfalse
because this should normally be handled by the outputParser- Parameters:
returnStdout
-
-
setReturnStderr
If set to true, this will return the stderr in the metadata viaExternalProcess.STD_ERR
. Default istrue
- Parameters:
returnStderr
-
-
setOutputParser
This parser is called on the output of the process. If the process writes to an output file, specified byOUTPUT_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
-
initialize
- Specified by:
initialize
in interfaceInitializable
- Parameters:
params
- params to use for initialization- Throws:
TikaConfigException
-
checkInitialization
public void checkInitialization(InitializableProblemHandler problemHandler) throws TikaConfigException - Specified by:
checkInitialization
in interfaceInitializable
- Parameters:
problemHandler
- if there is a problem and no custom initializableProblemHandler has been configured via Initializable parameters, this is called to respond.- Throws:
TikaConfigException
-