Top Description Inners Fields Constructors Methods
com.fasterxml.jackson.databind.deser

public Class DataFormatReaders

extends Object
Class Inheritance
Imports
java.io.ByteArrayInputStream, .IOException, .InputStream, java.util.Collection, com.fasterxml.jackson.core.*, com.fasterxml.jackson.core.format.*, com.fasterxml.jackson.core.io.MergedStream, com.fasterxml.jackson.databind.*

Alternative to DataFormatDetector that needs to be used when using data-binding.
Since
2.1

Nested and Inner Type Summary

Modifier and TypeClass and Description
protected static class
DataFormatReaders.AccessorForReader

We need sub-class here as well, to be able to access efficiently.

public static class

Field Summary

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

protected final ObjectReader[]
_readers

Ordered list of readers which both represent data formats to detect (in precedence order, starting with highest) and contain factories used for actual detection.

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
DataFormatReaders(ObjectReader[] detectors, MatchStrength optMatch, MatchStrength minMatch, int maxInputLookahead)

Method Summary

Modifier and TypeMethod and Description
private DataFormatReaders.Match
public DataFormatReaders.Match

Returns:

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

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

public DataFormatReaders.Match

Returns:

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

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

public DataFormatReaders.Match

Returns:

Matcher object which contains result; never null, even in cases where no match (with specified minimal match strength) is found.
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.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
public DataFormatReaders
with(ObjectReader[] readers)

public DataFormatReaders
public DataFormatReaders
withMaxInputLookahead(int lookaheadBytes)

public DataFormatReaders
public DataFormatReaders
public DataFormatReaders
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

_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,

_readersback to summary
protected final ObjectReader[] _readers

Ordered list of readers which both represent data formats to detect (in precedence order, starting with highest) and contain factories used for actual detection.

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

DataFormatReadersback to summary
public DataFormatReaders(ObjectReader... detectors)
DataFormatReadersback to summary
public DataFormatReaders(Collection<ObjectReader> detectors)
DataFormatReadersback to summary
private DataFormatReaders(ObjectReader[] detectors, MatchStrength optMatch, MatchStrength minMatch, int maxInputLookahead)

Method Detail

_findFormatback to summary
private DataFormatReaders.Match _findFormat(DataFormatReaders.AccessorForReader acc) throws IOException
findFormatback to summary
public DataFormatReaders.Match 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:DataFormatReaders.Match

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

findFormatback to summary
public DataFormatReaders.Match 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:DataFormatReaders.Match

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

findFormatback to summary
public DataFormatReaders.Match 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:DataFormatReaders.Match

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

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
withback to summary
public DataFormatReaders with(ObjectReader[] readers)
withback to summary
public DataFormatReaders with(DeserializationConfig config)
withMaxInputLookaheadback to summary
public DataFormatReaders withMaxInputLookahead(int lookaheadBytes)
withMinimalMatchback to summary
public DataFormatReaders withMinimalMatch(MatchStrength minMatch)
withOptimalMatchback to summary
public DataFormatReaders withOptimalMatch(MatchStrength optMatch)
withTypeback to summary
public DataFormatReaders withType(JavaType type)
com.fasterxml.jackson.databind.deser back to summary

protected Class DataFormatReaders.AccessorForReader

extends Std
Class Inheritance

We need sub-class here as well, to be able to access efficiently.

Field Summary

Inherited from com.fasterxml.jackson.core.format.InputAccessor.Std:
_buffer_bufferedEnd_bufferedStart_in_ptr

Constructor Summary

AccessConstructor and Description
public
AccessorForReader(InputStream in, byte[] buffer)

public
AccessorForReader(byte[] inputDocument)

public
AccessorForReader(byte[] inputDocument, int start, int len)

Method Summary

Modifier and TypeMethod and Description
public DataFormatReaders.Match
Inherited from com.fasterxml.jackson.core.format.InputAccessor.Std:
createMatcherhasMoreBytesnextBytereset

Constructor Detail

AccessorForReaderback to summary
public AccessorForReader(InputStream in, byte[] buffer)
AccessorForReaderback to summary
public AccessorForReader(byte[] inputDocument)
AccessorForReaderback to summary
public AccessorForReader(byte[] inputDocument, int start, int len)

Method Detail

createMatcherback to summary
public DataFormatReaders.Match createMatcher(ObjectReader match, MatchStrength matchStrength)
com.fasterxml.jackson.databind.deser back to summary

public Class DataFormatReaders.Match

extends Object
Class Inheritance

Result class, similar to DataFormatMatcher

Field Summary

Modifier and TypeField and Description
protected final byte[]
_bufferedData

Content read during format matching process

protected final int
_bufferedLength

Number of bytes available in buffer.

protected final int
_bufferedStart

Pointer to the first byte in buffer available for reading

protected final ObjectReader
_match

Factory that produced sufficient match (if any)

protected final MatchStrength
_matchStrength

Strength of match with _match

protected final InputStream

Constructor Summary

AccessConstructor and Description
protected
Match(InputStream in, byte[] buffered, int bufferedStart, int bufferedLength, ObjectReader match, MatchStrength strength)

Method Summary

Modifier and TypeMethod and Description
public JsonParser
createParserWithMatch()

Convenience method for trying to construct a JsonParser for parsing content which is assumed to be in detected data format.

public InputStream
getDataStream()

Method to use for accessing input for which format detection has been done.

public String
getMatchedFormatName()

Accessor for getting brief textual name of matched format if any (null if none).

public MatchStrength
getMatchStrength()

Method for accessing strength of the match, if any; if no match, will return MatchStrength#INCONCLUSIVE.

public ObjectReader
getReader()

Accessor for JsonFactory that represents format that data matched.

public boolean
hasMatch()

Accessor to use to see if any formats matched well enough with the input data.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

_bufferedDataback to summary
protected final byte[] _bufferedData

Content read during format matching process

_bufferedLengthback to summary
protected final int _bufferedLength

Number of bytes available in buffer.

_bufferedStartback to summary
protected final int _bufferedStart

Pointer to the first byte in buffer available for reading

_matchback to summary
protected final ObjectReader _match

Factory that produced sufficient match (if any)

_matchStrengthback to summary
protected final MatchStrength _matchStrength

Strength of match with _match

_originalStreamback to summary
protected final InputStream _originalStream

Constructor Detail

Matchback to summary
protected Match(InputStream in, byte[] buffered, int bufferedStart, int bufferedLength, ObjectReader match, MatchStrength strength)

Method Detail

createParserWithMatchback to summary
public JsonParser createParserWithMatch() throws IOException

Convenience method for trying to construct a JsonParser for parsing content which is assumed to be in detected data format. If no match was found, returns null.

getDataStreamback to summary
public InputStream getDataStream()

Method to use for accessing input for which format detection has been done. This must be used instead of using stream passed to detector unless given stream itself can do buffering. Stream will return all content that was read during matching process, as well as remaining contents of the underlying stream.

getMatchedFormatNameback to summary
public String getMatchedFormatName()

Accessor for getting brief textual name of matched format if any (null if none). Equivalent to:

   return hasMatch() ? getMatch().getFormatName() : null;
getMatchStrengthback to summary
public MatchStrength getMatchStrength()

Method for accessing strength of the match, if any; if no match, will return MatchStrength#INCONCLUSIVE.

getReaderback to summary
public ObjectReader getReader()

Accessor for JsonFactory that represents format that data matched.

hasMatchback to summary
public boolean hasMatch()

Accessor to use to see if any formats matched well enough with the input data.