Class DataFormatDetector
java.lang.Object
edu.internet2.middleware.grouperClientExt.com.fasterxml.jackson.core.format.DataFormatDetector
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 Summary
Modifier and TypeFieldDescriptionprotected final JsonFactory[]
Ordered list of factories which both represent data formats to detect (in precedence order, starting with highest) and are used for actual detection.protected final int
Maximum number of leading bytes of the input that we can read to determine data format.protected final MatchStrength
Strength of minimal match we accept as the answer, unless better matches are found.protected final MatchStrength
Strength of match we consider to be good enough to be used without checking any other formats.static final int
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. -
Constructor Summary
ConstructorDescriptionDataFormatDetector
(JsonFactory... detectors) DataFormatDetector
(Collection<JsonFactory> detectors) -
Method Summary
Modifier and TypeMethodDescriptionfindFormat
(byte[] fullInputData) Method to call to find format that given content (full document) has, as per configuration of this detector instance.findFormat
(byte[] fullInputData, int offset, int len) Method to call to find format that given content (full document) has, as per configuration of this detector instance.Method to call to find format that content (accessible via givenInputStream
) given has, as per configuration of this detector instance.toString()
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.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.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).
-
Field Details
-
DEFAULT_MAX_INPUT_LOOKAHEAD
public static final int DEFAULT_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.- See Also:
-
_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
Strength of match we consider to be good enough to be used without checking any other formats. Default value isMatchStrength.SOLID_MATCH
, -
_minimalMatch
Strength of minimal match we accept as the answer, unless better matches are found. Default value isMatchStrength.WEAK_MATCH
, -
_maxInputLookahead
protected final int _maxInputLookaheadMaximum number of leading bytes of the input that we can read to determine data format.Default value is
DEFAULT_MAX_INPUT_LOOKAHEAD
.
-
-
Constructor Details
-
DataFormatDetector
-
DataFormatDetector
-
-
Method Details
-
withOptimalMatch
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).- Parameters:
optMatch
- Optimal match level to use- Returns:
- Format detector instance with specified optimal match level
-
withMinimalMatch
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.- Parameters:
minMatch
- Minimum match level to use- Returns:
- Format detector instance with specified minimum match level
-
withMaxInputLookahead
Method that will return a detector instance that allows detectors to read up to specified number of bytes when determining format match strength.- Parameters:
lookaheadBytes
- Amount of look-ahead allowed- Returns:
- Format detector instance with specified lookahead settings
-
findFormat
Method to call to find format that content (accessible via givenInputStream
) given has, as per configuration of this detector instance.- Parameters:
in
- InputStream from which to read initial content- Returns:
- Matcher object which contains result; never null, even in cases where no match (with specified minimal match strength) is found.
- Throws:
IOException
- for read I/O problems
-
findFormat
Method to call to find format that given content (full document) has, as per configuration of this detector instance.- Parameters:
fullInputData
- Full contents to use for format detection- Returns:
- Matcher object which contains result; never null, even in cases where no match (with specified minimal match strength) is found.
- Throws:
IOException
- for read I/O problems
-
findFormat
Method to call to find format that given content (full document) has, as per configuration of this detector instance.- Parameters:
fullInputData
- Full contents to use for format detectionoffset
- Offset of the first content bytelen
- Length of content- Returns:
- Matcher object which contains result; never null, even in cases where no match (with specified minimal match strength) is found.
- Throws:
IOException
- for read I/O problems- Since:
- 2.1
-
toString
-