Class MagikaDetector

java.lang.Object
org.apache.tika.detect.magika.MagikaDetector
All Implemented Interfaces:
Serializable, SelfConfiguring, 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:
  • Field Details

    • MAGIKA_PREFIX

      public static final String MAGIKA_PREFIX
      See Also:
    • 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
  • Constructor Details

    • MagikaDetector

      public MagikaDetector()
      Default constructor.
    • MagikaDetector

      public MagikaDetector(JsonConfig jsonConfig)
      Constructor for JSON configuration. Requires tika-serialization on the classpath.
      Parameters:
      jsonConfig - JSON configuration
  • Method Details

    • checkHasMagika

      public static boolean checkHasMagika(String magikaCommandPath)
    • detect

      public MediaType detect(TikaInputStream tis, Metadata metadata, ParseContext parseContext) throws IOException
      Description copied from interface: Detector
      Detects the content type of the given input document. Returns application/octet-stream if 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 detector is expected to mark the stream before reading any bytes from it, and to reset the 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:
      detect in interface Detector
      Parameters:
      tis - document input stream, or null
      metadata - input metadata for the document
      parseContext - the parse context
      Returns:
      mime as identified by the file command or application/octet-stream otherwise
      Throws:
      IOException
    • getDefaultConfig

      public MagikaDetector.Config getDefaultConfig()
    • processResult

      protected static MediaType processResult(FileProcessResult result, Metadata metadata, boolean returnMime)