Package org.apache.tika.detect.magika
Class MagikaDetector
- java.lang.Object
-
- org.apache.tika.detect.magika.MagikaDetector
-
- All Implemented Interfaces:
Serializable,Detector
public class MagikaDetector extends Object implements Detector
Simple wrapper around Google's magika: https://github.com/google/magika The tool must be installed on the host where Tika is running. The default behavior is to run detection, report the results in the metadata and then return null so that other detectors will be used.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static PropertyMAGIKA_DESCRIPTIONstatic PropertyMAGIKA_ERRORSstatic PropertyMAGIKA_GROUPstatic PropertyMAGIKA_IS_TEXTstatic PropertyMAGIKA_LABELstatic PropertyMAGIKA_MIMEstatic StringMAGIKA_PREFIXstatic PropertyMAGIKA_SCOREstatic PropertyMAGIKA_STATUSstatic PropertyMAGIKA_VERSION
-
Constructor Summary
Constructors Constructor Description MagikaDetector()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static booleancheckHasMagika(String magikaCommandPath)MediaTypedetect(InputStream input, Metadata metadata)Detects the content type of the given input document.booleanisUseMime()protected static MediaTypeprocessResult(FileProcessResult result, Metadata metadata, boolean returnMime)voidsetMagikaPath(String fileCommandPath)voidsetMaxBytes(int maxBytes)If this is not called on a TikaInputStream, this detector will spool up to this many bytes to a file to be detected by the 'file' command.voidsetTimeoutMs(long timeoutMs)voidsetUseMime(boolean useMime)As default behavior, Tika runs magika to add its detection to the metadata, but NOT to use detection in determining parsers etc.
-
-
-
Field Detail
-
MAGIKA_PREFIX
public static final String MAGIKA_PREFIX
- See Also:
- Constant Field Values
-
MAGIKA_STATUS
public static Property MAGIKA_STATUS
-
MAGIKA_DESCRIPTION
public static Property MAGIKA_DESCRIPTION
-
MAGIKA_SCORE
public static Property MAGIKA_SCORE
-
MAGIKA_GROUP
public static Property MAGIKA_GROUP
-
MAGIKA_LABEL
public static Property MAGIKA_LABEL
-
MAGIKA_MIME
public static Property MAGIKA_MIME
-
MAGIKA_IS_TEXT
public static Property MAGIKA_IS_TEXT
-
MAGIKA_ERRORS
public static Property MAGIKA_ERRORS
-
MAGIKA_VERSION
public static Property MAGIKA_VERSION
-
-
Method Detail
-
checkHasMagika
public static boolean checkHasMagika(String magikaCommandPath)
-
detect
public MediaType detect(InputStream input, Metadata metadata) throws IOException
Description copied from interface:DetectorDetects the content type of the given input document. Returnsapplication/octet-streamif the type of the document can not be detected.If the document input stream is not available, then the first argument may be
null. Otherwise the detector may read bytes from the start of the stream to help in type detection. The given stream is guaranteed to support themark featureand the detector is expected tomarkthe stream before reading any bytes from it, and toresetthe stream before returning. The stream must not be closed by the detector.The given input metadata is only read, not modified, by the detector.
- Specified by:
detectin interfaceDetector- Parameters:
input- document input stream, ornullmetadata- input metadata for the document- Returns:
- mime as identified by the file command or application/octet-stream otherwise
- Throws:
IOException
-
setUseMime
@Field public void setUseMime(boolean useMime)
As default behavior, Tika runs magika to add its detection to the metadata, but NOT to use detection in determining parsers etc. If this is set totrue, this detector will return the first mime detected by magika and that mime will be used by the AutoDetectParser to select the appropriate parser.- Parameters:
useMime-
-
isUseMime
public boolean isUseMime()
-
processResult
protected static MediaType processResult(FileProcessResult result, Metadata metadata, boolean returnMime)
-
setMaxBytes
@Field public void setMaxBytes(int maxBytes)
If this is not called on a TikaInputStream, this detector will spool up to this many bytes to a file to be detected by the 'file' command.- Parameters:
maxBytes-
-
setTimeoutMs
@Field public void setTimeoutMs(long timeoutMs)
-
-