Class DataFormatDetector


  • public class DataFormatDetector
    extends Object
    Simple helper class that allows data format (content type) auto-detection, given an ordered set of JsonFactory instances to use for actual low-level detection.
    • Field Detail

      • DEFAULT_MAX_INPUT_LOOKAHEAD

        public static final int DEFAULT_MAX_INPUT_LOOKAHEAD
        By default we will look ahead at most 64 bytes; in most cases, much less (4 bytes or so) is needed, but we will allow bit more leniency to support data formats that need more complex heuristics.
        See Also:
        Constant Field Values
    • Constructor Detail

      • DataFormatDetector

        public DataFormatDetector​(JsonFactory... detectors)
    • Method Detail

      • withOptimalMatch

        public DataFormatDetector withOptimalMatch​(MatchStrength optMatch)
        Method that will return a detector instance that uses given optimal match level (match that is considered sufficient to return, without trying to find stronger matches with other formats).
      • withMinimalMatch

        public DataFormatDetector withMinimalMatch​(MatchStrength minMatch)
        Method that will return a detector instance that uses given minimal match level; match that may be returned unless a stronger match is found with other format detectors.
      • withMaxInputLookahead

        public DataFormatDetector withMaxInputLookahead​(int lookaheadBytes)
        Method that will return a detector instance that allows detectors to read up to specified number of bytes when determining format match strength.
      • findFormat

        public DataFormatMatcher findFormat​(InputStream in)
                                     throws IOException
        Method to call to find format that content (accessible via given InputStream) given has, as per configuration of this detector instance.
        Returns:
        Matcher object which contains result; never null, even in cases where no match (with specified minimal match strength) is found.
        Throws:
        IOException
      • findFormat

        public DataFormatMatcher findFormat​(byte[] fullInputData)
                                     throws IOException
        Method to call to find format that given content (full document) has, as per configuration of this detector instance.
        Returns:
        Matcher object which contains result; never null, even in cases where no match (with specified minimal match strength) is found.
        Throws:
        IOException
      • findFormat

        public DataFormatMatcher findFormat​(byte[] fullInputData,
                                            int offset,
                                            int len)
                                     throws IOException
        Method to call to find format that given content (full document) has, as per configuration of this detector instance.
        Returns:
        Matcher object which contains result; never null, even in cases where no match (with specified minimal match strength) is found.
        Throws:
        IOException
        Since:
        2.1