Package org.apache.tika.detect
Class MagicDetector
- java.lang.Object
- 
- org.apache.tika.detect.MagicDetector
 
- 
- All Implemented Interfaces:
- Serializable,- Detector
 
 public class MagicDetector extends Object implements Detector Content type detection based on magic bytes, i.e. type-specific patterns near the beginning of the document input stream.Because this works on bytes, not characters, by default any string matching is done as ISO_8859_1. To use an explicit different encoding, supply a type other than "string" / "stringignorecase" - Since:
- Apache Tika 0.3
- See Also:
- Serialized Form
 
- 
- 
Constructor SummaryConstructors Constructor Description MagicDetector(MediaType type, byte[] pattern)Creates a detector for input documents that have the exact given byte pattern at the beginning of the document stream.MagicDetector(MediaType type, byte[] pattern, byte[] mask, boolean isRegex, boolean isStringIgnoreCase, int offsetRangeBegin, int offsetRangeEnd)Creates a detector for input documents that meet the specified magic match.MagicDetector(MediaType type, byte[] pattern, byte[] mask, boolean isRegex, int offsetRangeBegin, int offsetRangeEnd)Creates a detector for input documents that meet the specified magic match.MagicDetector(MediaType type, byte[] pattern, byte[] mask, int offsetRangeBegin, int offsetRangeEnd)Creates a detector for input documents that meet the specified magic match.MagicDetector(MediaType type, byte[] pattern, int offset)Creates a detector for input documents that have the exact given byte pattern at the given offset of the document stream.
 - 
Method SummaryAll Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description MediaTypedetect(InputStream input, Metadata metadata)Detects the content type of the given input document.intgetLength()static MagicDetectorparse(MediaType mediaType, String type, String offset, String value, String mask)StringtoString()Returns a string representation of the Detection Rule.
 
- 
- 
- 
Constructor Detail- 
MagicDetectorpublic MagicDetector(MediaType type, byte[] pattern) Creates a detector for input documents that have the exact given byte pattern at the beginning of the document stream.- Parameters:
- type- matching media type
- pattern- magic match pattern
 
 - 
MagicDetectorpublic MagicDetector(MediaType type, byte[] pattern, int offset) Creates a detector for input documents that have the exact given byte pattern at the given offset of the document stream.- Parameters:
- type- matching media type
- pattern- magic match pattern
- offset- offset of the pattern match
 
 - 
MagicDetectorpublic MagicDetector(MediaType type, byte[] pattern, byte[] mask, int offsetRangeBegin, int offsetRangeEnd) Creates a detector for input documents that meet the specified magic match.patternmust NOT be a regular expression. Constructor maintained for legacy reasons.
 - 
MagicDetectorpublic MagicDetector(MediaType type, byte[] pattern, byte[] mask, boolean isRegex, int offsetRangeBegin, int offsetRangeEnd) Creates a detector for input documents that meet the specified magic match.
 - 
MagicDetectorpublic MagicDetector(MediaType type, byte[] pattern, byte[] mask, boolean isRegex, boolean isStringIgnoreCase, int offsetRangeBegin, int offsetRangeEnd) Creates a detector for input documents that meet the specified magic match.
 
- 
 - 
Method Detail- 
parsepublic static MagicDetector parse(MediaType mediaType, String type, String offset, String value, String mask) 
 - 
detectpublic 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 interface- Detector
- Parameters:
- input- document input stream, or- null
- metadata- ignored
- Returns:
- detected media type, or application/octet-stream
- Throws:
- IOException- if the document input stream could not be read
 
 - 
getLengthpublic int getLength() 
 
- 
 
-