Top Description Fields Constructors Methods
com.fasterxml.jackson.core.format

public Class DataFormatDetector

extends Object
Class Inheritance
Imports
java.io.*, java.util.*, com.fasterxml.jackson.core.*

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 TypeField and Description
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.

protected final int
_maxInputLookahead

Maximum number of leading bytes of the input that we can read to determine data format.

protected final MatchStrength
_minimalMatch

Strength of minimal match we accept as the answer, unless better matches are found.

protected final MatchStrength
_optimalMatch

Strength of match we consider to be good enough to be used without checking any other formats.

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.

Constructor Summary

AccessConstructor and Description
public
public
private
DataFormatDetector(JsonFactory[] detectors, MatchStrength optMatch, MatchStrength minMatch, int maxInputLookahead)

Method Summary

Modifier and TypeMethod and Description
private DataFormatMatcher
public DataFormatMatcher

Returns:

Matcher object which contains result; never null, even in cases where no match (with specified minimal match strength) is found.
findFormat
(InputStream
InputStream from which to read initial content
in
)

Method to call to find format that content (accessible via given InputStream) given has, as per configuration of this detector instance.

public DataFormatMatcher

Returns:

Matcher object which contains result; never null, even in cases where no match (with specified minimal match strength) is found.
findFormat
(byte[]
Full contents to use for format detection
fullInputData
)

Method to call to find format that given content (full document) has, as per configuration of this detector instance.

public DataFormatMatcher

Returns:

Matcher object which contains result; never null, even in cases where no match (with specified minimal match strength) is found.
findFormat
(byte[]
Full contents to use for format detection
fullInputData
,
int
Offset of the first content byte
offset
,
int
Length of content
len
)

Method to call to find format that given content (full document) has, as per configuration of this detector instance.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
public DataFormatDetector

Returns:

Format detector instance with specified lookahead settings
withMaxInputLookahead
(int
Amount of look-ahead allowed
lookaheadBytes
)

Method that will return a detector instance that allows detectors to read up to specified number of bytes when determining format match strength.

public DataFormatDetector

Returns:

Format detector instance with specified minimum match level
withMinimalMatch
(MatchStrength
Minimum match level to use
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.

public DataFormatDetector

Returns:

Format detector instance with specified optimal match level
withOptimalMatch
(MatchStrength
Optimal match level to use
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).

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

_detectorsback to summary
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.

_maxInputLookaheadback to summary
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.

_minimalMatchback to summary
protected final MatchStrength _minimalMatch

Strength of minimal match we accept as the answer, unless better matches are found. Default value is MatchStrength#WEAK_MATCH,

_optimalMatchback to summary
protected final MatchStrength _optimalMatch

Strength of match we consider to be good enough to be used without checking any other formats. Default value is MatchStrength#SOLID_MATCH,

DEFAULT_MAX_INPUT_LOOKAHEADback to summary
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.

Constructor Detail

DataFormatDetectorback to summary
public DataFormatDetector(JsonFactory... detectors)
DataFormatDetectorback to summary
public DataFormatDetector(Collection<JsonFactory> detectors)
DataFormatDetectorback to summary
private DataFormatDetector(JsonFactory[] detectors, MatchStrength optMatch, MatchStrength minMatch, int maxInputLookahead)

Method Detail

_findFormatback to summary
private DataFormatMatcher _findFormat(InputAccessor.Std acc) throws IOException
findFormatback to summary
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.

Parameters
in:InputStream

InputStream from which to read initial content

Returns:DataFormatMatcher

Matcher object which contains result; never null, even in cases where no match (with specified minimal match strength) is found.

Exceptions
IOException:
for read I/O problems
findFormatback to summary
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.

Parameters
fullInputData:byte[]

Full contents to use for format detection

Returns:DataFormatMatcher

Matcher object which contains result; never null, even in cases where no match (with specified minimal match strength) is found.

Exceptions
IOException:
for read I/O problems
findFormatback to summary
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.

Parameters
fullInputData:byte[]

Full contents to use for format detection

offset:int

Offset of the first content byte

len:int

Length of content

Returns:DataFormatMatcher

Matcher object which contains result; never null, even in cases where no match (with specified minimal match strength) is found.

Exceptions
IOException:
for read I/O problems
Since
2.1
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

Annotations
@Override
withMaxInputLookaheadback to summary
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.

Parameters
lookaheadBytes:int

Amount of look-ahead allowed

Returns:DataFormatDetector

Format detector instance with specified lookahead settings

withMinimalMatchback to summary
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.

Parameters
minMatch:MatchStrength

Minimum match level to use

Returns:DataFormatDetector

Format detector instance with specified minimum match level

withOptimalMatchback to summary
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).

Parameters
optMatch:MatchStrength

Optimal match level to use

Returns:DataFormatDetector

Format detector instance with specified optimal match level