Package org.codehaus.jackson.format
Class DataFormatDetector
- java.lang.Object
-
- org.codehaus.jackson.format.DataFormatDetector
-
public class DataFormatDetector extends java.lang.ObjectSimple helper class that allows data format (content type) auto-detection, given an ordered set ofJsonFactoryinstances to use for actual low-level detection.- Since:
- 1.7
-
-
Field Summary
Fields Modifier and Type Field Description protected JsonFactory[]_detectorsOrdered list of factories which both represent data formats to detect (in precedence order, starting with highest) and are used for actual detection.protected int_maxInputLookaheadMaximum number of leading bytes of the input that we can read to determine data format.protected MatchStrength_minimalMatchStrength of minimal match we accept as the answer, unless better matches are found.protected MatchStrength_optimalMatchStrength of match we consider to be good enough to be used without checking any other formats.static intDEFAULT_MAX_INPUT_LOOKAHEADBy 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.
-
Constructor Summary
Constructors Constructor Description DataFormatDetector(java.util.Collection<JsonFactory> detectors)DataFormatDetector(JsonFactory... detectors)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description DataFormatMatcherfindFormat(byte[] fullInputData)Method to call to find format that given content (full document) has, as per configuration of this detector instance.DataFormatMatcherfindFormat(java.io.InputStream in)Method to call to find format that content (accessible via givenInputStream) given has, as per configuration of this detector instance.DataFormatDetectorwithMaxInputLookahead(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.DataFormatDetectorwithMinimalMatch(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.DataFormatDetectorwithOptimalMatch(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).
-
-
-
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
-
_detectors
protected final JsonFactory[] _detectors
Ordered list of factories which both represent data formats to detect (in precedence order, starting with highest) and are used for actual detection.
-
_optimalMatch
protected final MatchStrength _optimalMatch
Strength of match we consider to be good enough to be used without checking any other formats. Default value isMatchStrength.SOLID_MATCH,
-
_minimalMatch
protected final MatchStrength _minimalMatch
Strength of minimal match we accept as the answer, unless better matches are found. Default value isMatchStrength.WEAK_MATCH,
-
_maxInputLookahead
protected final int _maxInputLookahead
Maximum number of leading bytes of the input that we can read to determine data format.Default value is
DEFAULT_MAX_INPUT_LOOKAHEAD.
-
-
Constructor Detail
-
DataFormatDetector
public DataFormatDetector(JsonFactory... detectors)
-
DataFormatDetector
public DataFormatDetector(java.util.Collection<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(java.io.InputStream in) throws java.io.IOException
Method to call to find format that content (accessible via givenInputStream) 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:
java.io.IOException
-
findFormat
public DataFormatMatcher findFormat(byte[] fullInputData) throws java.io.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:
java.io.IOException
-
-