Class RawTiffDetector

java.lang.Object
org.apache.tika.detect.image.RawTiffDetector
All Implemented Interfaces:
Serializable, SelfConfiguring, Detector

public class RawTiffDetector extends Object implements Detector
Tells the TIFF-based raw camera formats (Nikon NEF/NRW, Pentax PEF/PTX, Sony ARW/SRF/SR2, Samsung SRW, Adobe DNG) from a plain TIFF by content, so they are recognized without a file name (TIKA-4861). They share the TIFF magic; what differs is the image directory:
  1. a DNGVersion tag (0xC612) makes a DNG, whoever wrote it;
  2. a vendor-specific Compression value (0x0103) in any IFD names the format: 34713 Nikon, 32767 Sony, 65535 Pentax, 32770 and 32772 Samsung (this is how ExifTool identifies them);
  3. otherwise sensor data in any IFD marks a raw, and the Make tag (0x010F) picks the vendor: an image with PhotometricInterpretation 32803 (CFA) or 34892 (LinearRaw), or a full-resolution image (NewSubfileType 0) of one 9 to 16 bit sample without any PhotometricInterpretation, which a regular TIFF must have (Samsung NX1). This catches the uncompressed variants. A plain TIFF from the same camera has RGB data and stays image/tiff.
The detector reads the stream into memory as far as the directories require, up to MAX_PREFIX_LENGTH, and walks the IFD chain and the SubIFDs (0x014A) inside that prefix; raw files keep their directories ahead of the sensor data, though behind the embedded previews (some hundred KB). A plain TIFF with its directory at the start costs a few KB. Anything it cannot decide is left to the other detectors as application/octet-stream. Canon CR2 has a fixed signature and is matched by the mime magic instead.
See Also:
  • Constructor Details

    • RawTiffDetector

      public RawTiffDetector()
  • Method Details

    • 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:
      detected media type, or application/octet-stream
      Throws:
      IOException - if the document input stream could not be read