- All Implemented Interfaces:
Serializable,Snapshottable<TokenStreamFactory>,Versioned
- Direct Known Subclasses:
DecorableTSFactory
JsonParser)
and token writer (aka generator, JsonGenerator)
instances.
Factory instances are thread-safe and reusable after configuration (if any). Typically applications and services use only a single globally shared factory instance, unless they need differently configured factories. Factory reuse is important if efficiency matters; most recycling of expensive construct is done on per-factory basis.
Creation of a factory instance is a light-weight operation.
- Since:
- 3.0 (refactored out of
JsonFactory) - See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumEnumeration that defines all on/off features that can only be changed forTokenStreamFactory. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final ErrorReportConfigurationActive ErrorReportConfiguration to use.protected final intCurrently enabledTokenStreamFactory.Features features as a bitmask.protected final intSet of format-specific read features enabled, as bitmask.protected final intSet of format-specific write features enabled, as bitmask.protected final RecyclerPool<BufferRecycler>protected final StreamReadConstraintsActive StreamReadConstraints to use.protected final intCurrently enabledStreamReadFeatures as a bitmask.protected final StreamWriteConstraintsActive StreamWriteConstraints to use.protected final intCurrently enabledStreamWriteFeatures as a bitmask.protected static final intBitfield (set of flags) of all factory features that are enabled by default.protected static final intBitfield (set of flags) of all parser features that are enabled by default.protected static final intBitfield (set of flags) of all generator features that are enabled by default.static final ObjectWriteContextShareable stateles "empty"ObjectWriteContextObject, passed in cases where caller had not passed actual context - "null object" of sort. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedTokenStreamFactory(StreamReadConstraints src, StreamWriteConstraints swc, ErrorReportConfiguration erc, int formatReadFeatures, int formatWriteFeatures) Default constructor used to create factory instances.protectedConstructor used if a snapshot is created, or possibly for sub-classing or wrapping (delegating)protectedTokenStreamFactory(TSFBuilder<?, ?> baseBuilder) Constructors used byTSFBuilderfor instantiation. -
Method Summary
Modifier and TypeMethodDescriptionprotected void_checkRangeBoundsForByteArray(byte[] data, int offset, int len) protected void_checkRangeBoundsForCharArray(char[] data, int offset, int len) protected abstract ContentReference_createContentReference(Object contentRef) Overridable factory method for constructingContentReferenceto pass to parser or generator being created; used in cases where no offset or length is applicable (either irrelevant, or full contents assumed).protected abstract ContentReference_createContentReference(Object contentRef, int offset, int length) Overridable factory method for constructingContentReferenceto pass to parser or generator being created; used in cases where input comes in a static buffer with relevant offset and length.protected IOContext_createContext(ContentReference contentRef, boolean resourceManaged) Overridable factory method that actually instantiates desired context object.protected IOContext_createContext(ContentReference contentRef, boolean resourceManaged, JsonEncoding enc) Overridable factory method that actually instantiates desired context object.protected OutputStreamprotected InputStreamHelper methods used for constructing anInputStreamfor parsers to use, when input is to be read from givenFile.protected OutputStreamHelper methods used for constructing anOutputStreamfor generator to use, when target is to be written into givenFile.Method used by factory to create buffer recycler instances for parsers and generators.Accessor for getting access toRecyclerPoolfor gettingBufferRecyclerinstance to use.protected InputStreamDeprecated.Since 3.0protected InputStreamprotected OutputStreamprotected <T> T_reportRangeError(String msg) protected <T> Tprotected <T> T_unsupported(String str, Object... args) protected JacksonExceptionabstract booleanIntrospection method that higher-level functionality may call to see whether underlying data format can read and write binary data natively; that is, embedded it as-is without using encodings such as Base64.abstract booleanIntrospection method that can be used to check whether this factory can create non-blocking parsers: parsers that do not use blocking I/O abstractions but instead use aNonBlockingInputFeeder.abstract booleancanUseSchema(FormatSchema schema) Method that can be used to quickly check whether given schema is something that parsers and/or generators constructed by this factory could use.constructCINameMatcher(List<Named> matches, boolean alreadyInterned, Locale locale) Factory method for constructing case-insensitivePropertyNameMatcherfor given names.constructNameMatcher(List<Named> matches, boolean alreadyInterned) Factory method for constructing case-sensitivePropertyNameMatcherfor given names.abstract TokenStreamFactorycopy()Method similar tosnapshot(), but one that forces creation of actual new copy that does NOT share any state, even non-visible to calling code, such as symbol table reuse.Deprecated.createGenerator(OutputStream out, JsonEncoding enc) Deprecated.Deprecated.createGenerator(ObjectWriteContext writeCtxt, DataOutput out) Method for constructing generator that writes content into specifiedDataOutput, using UTF-8 encoding (with formats where encoding is user-configurable).abstract JsonGeneratorcreateGenerator(ObjectWriteContext writeCtxt, File f, JsonEncoding enc) Method for constructing generator that writes contents to specified file, overwriting contents it might have (or creating it if such file does not yet exist).createGenerator(ObjectWriteContext writeCtxt, OutputStream out) Method for constructing generator that writes contents using specifiedOutputStream.abstract JsonGeneratorcreateGenerator(ObjectWriteContext writeCtxt, OutputStream out, JsonEncoding enc) Method for constructing generator that writes contents using specifiedOutputStreamwith specified textual encoding (if applicable).abstract JsonGeneratorcreateGenerator(ObjectWriteContext writeCtxt, Writer w) Method for constructing generator that writes contents using specifiedWriter.abstract JsonGeneratorcreateGenerator(ObjectWriteContext writeCtxt, Path p, JsonEncoding enc) Method for constructing generator that writes contents to specified path, overwriting contents it might have (or creating it if such path does not yet exist).<P extends JsonParser & ByteArrayFeeder>
POptional method for constructing parser for non-blocking parsing viaByteArrayFeederinterface (accessed usingJsonParser.nonBlockingInputFeeder()from constructed instance).<P extends JsonParser & ByteArrayFeeder>
POptional method for constructing parser for non-blocking parsing viaByteBufferFeederinterface (accessed usingJsonParser.nonBlockingInputFeeder()from constructed instance).createParser(byte[] content) Deprecated.Since 3.0 usecreateParser(ObjectReadContext,byte[])createParser(byte[] content, int offset, int len) Deprecated.Since 3.0 usecreateParser(ObjectReadContext,byte[],int,int)createParser(char[] content) Deprecated.Since 3.0 usecreateParser(ObjectReadContext,char[])createParser(char[] content, int offset, int len) Deprecated.Since 3.0 usecreateParser(ObjectReadContext,char[],int,int)createParser(File f) Deprecated.Since 3.0 usecreateParser(ObjectReadContext,java.io.File)Deprecated.Since 3.0 usecreateParser(ObjectReadContext,java.io.InputStream)Deprecated.Since 3.0 usecreateParser(ObjectReadContext,java.io.Reader)createParser(String content) Deprecated.Since 3.0 usecreateParser(ObjectReadContext,String)createParser(ObjectReadContext readCtxt, byte[] data) Method for constructing parser for parsing the contents of given byte array.abstract JsonParsercreateParser(ObjectReadContext readCtxt, byte[] content, int offset, int len) Method for constructing parser for parsing the contents of given byte array.createParser(ObjectReadContext readCtxt, char[] content) Method for constructing parser for parsing contents of given char array.abstract JsonParsercreateParser(ObjectReadContext readCtxt, char[] content, int offset, int len) Method for constructing parser for parsing contents of given char array.abstract JsonParsercreateParser(ObjectReadContext readCtxt, DataInput in) Optional method for constructing parser for reading contents from specifiedDataInputinstance.abstract JsonParsercreateParser(ObjectReadContext readCtxt, File f) Method for constructing parser instance to decode contents of specified file.abstract JsonParsercreateParser(ObjectReadContext readCtxt, InputStream in) Method for constructing JSON parser instance to parse the contents accessed via specified input stream.abstract JsonParsercreateParser(ObjectReadContext readCtxt, Reader r) Method for constructing parser for parsing the contents accessed via specified Reader.abstract JsonParsercreateParser(ObjectReadContext readCtxt, String content) Method for constructing parser for parsing contents of given String.abstract JsonParsercreateParser(ObjectReadContext readCtxt, Path p) Method for constructing parser instance to decode contents of specified path.final intabstract StringMethod that returns short textual id identifying format this factory supports.intClass<? extends FormatFeature>Method for accessing kind ofFormatFeaturethat a parserJsonParserproduced by this factory would accept, if any;nullreturned if none.intClass<? extends FormatFeature>Method for accessing kind ofFormatFeaturethat a parserJsonGeneratorproduced by this factory would accept, if any;nullreturned if none.final intfinal intfinal booleanChecked whether specified parser feature is enabled.final booleanChecked whether specified parser feature is enabled.final booleanChecked whether specified parser feature is enabled.abstract TSFBuilder<?,?> rebuild()Method that can be used to create differently configured stream factories: it will create and return a Builder instance with exact settings of this stream factory.booleanIntrospection method that higher-level functionality may call to see whether underlying data format requires a stable ordering of object properties or not.abstract TokenStreamFactorysnapshot()Method for constructing a newTokenStreamFactorythat has the same settings as this instance, but is otherwise independent (i.e. nothing is actually shared, symbol tables are separate).abstract Versionversion()Method called to detect version of the component that implements this interface; returned version should never be null, but may return specific "not available" instance (seeVersionfor details).
-
Field Details
-
EMPTY_WRITE_CONTEXT
Shareable stateles "empty"ObjectWriteContextObject, passed in cases where caller had not passed actual context - "null object" of sort. -
DEFAULT_FACTORY_FEATURE_FLAGS
protected static final int DEFAULT_FACTORY_FEATURE_FLAGSBitfield (set of flags) of all factory features that are enabled by default. -
DEFAULT_STREAM_READ_FEATURE_FLAGS
protected static final int DEFAULT_STREAM_READ_FEATURE_FLAGSBitfield (set of flags) of all parser features that are enabled by default. -
DEFAULT_STREAM_WRITE_FEATURE_FLAGS
protected static final int DEFAULT_STREAM_WRITE_FEATURE_FLAGSBitfield (set of flags) of all generator features that are enabled by default. -
_factoryFeatures
protected final int _factoryFeaturesCurrently enabledTokenStreamFactory.Features features as a bitmask. -
_streamReadFeatures
protected final int _streamReadFeaturesCurrently enabledStreamReadFeatures as a bitmask. -
_streamWriteFeatures
protected final int _streamWriteFeaturesCurrently enabledStreamWriteFeatures as a bitmask. -
_formatReadFeatures
protected final int _formatReadFeaturesSet of format-specific read features enabled, as bitmask. -
_formatWriteFeatures
protected final int _formatWriteFeaturesSet of format-specific write features enabled, as bitmask. -
_recyclerPool
-
_streamReadConstraints
Active StreamReadConstraints to use. -
_streamWriteConstraints
Active StreamWriteConstraints to use. -
_errorReportConfiguration
Active ErrorReportConfiguration to use.
-
-
Constructor Details
-
TokenStreamFactory
protected TokenStreamFactory(StreamReadConstraints src, StreamWriteConstraints swc, ErrorReportConfiguration erc, int formatReadFeatures, int formatWriteFeatures) Default constructor used to create factory instances. Creation of a factory instance is a light-weight operation, but it is still a good idea to reuse limited number of factory instances (and quite often just a single instance): factories are used as context for storing some reused processing objects (such as symbol tables parsers use) and this reuse only works within context of a single factory instance.- Parameters:
src- StreamReadConstraints to use with parsers factory createsswc- StreamWriteConstraints to use with generators factory createserc- ErrorReportConfiguration to use with parsers factory createsformatReadFeatures- Bitmask of format-specific read features enabledformatWriteFeatures- Bitmask of format-specific write features enabled
-
TokenStreamFactory
Constructors used byTSFBuilderfor instantiation. Base builder is passed as-is to try to make interface between base types and implementations less likely to change (given that sub-classing is a fragile way to do it): if and when new general-purpose properties are added, implementation classes do not have to use different constructors.- Parameters:
baseBuilder- Builder with configuration to use- Since:
- 3.0
-
TokenStreamFactory
Constructor used if a snapshot is created, or possibly for sub-classing or wrapping (delegating)- Parameters:
src- Source factory with configuration to copy
-
-
Method Details
-
copy
Method similar tosnapshot(), but one that forces creation of actual new copy that does NOT share any state, even non-visible to calling code, such as symbol table reuse.Implementation should be functionally equivalent to:
factoryInstance.rebuild().build();- Returns:
- Newly constructed stream factory instance of same type as this one, with identical configuration settings
-
snapshot
Method for constructing a newTokenStreamFactorythat has the same settings as this instance, but is otherwise independent (i.e. nothing is actually shared, symbol tables are separate).Although assumption is that all factories are immutable -- and that we could usually simply return `this` -- method is left unimplemented at this level to make implementors aware of requirement to consider immutability.
- Specified by:
snapshotin interfaceSnapshottable<TokenStreamFactory>- Returns:
- This factory instance to allow call chaining
- Since:
- 3.0
-
rebuild
Method that can be used to create differently configured stream factories: it will create and return a Builder instance with exact settings of this stream factory.- Returns:
- Builder instance initialized with configuration this stream factory has
- Since:
- 3.0
-
requiresPropertyOrdering
public boolean requiresPropertyOrdering()Introspection method that higher-level functionality may call to see whether underlying data format requires a stable ordering of object properties or not. This is usually used for determining whether to force a stable ordering (like alphabetic ordering by name) if no ordering if explicitly specified.- Returns:
- Whether format supported by this factory requires Object properties to be ordered.
-
canHandleBinaryNatively
public abstract boolean canHandleBinaryNatively()Introspection method that higher-level functionality may call to see whether underlying data format can read and write binary data natively; that is, embedded it as-is without using encodings such as Base64.- Returns:
- Whether format supported by this factory supports native binary content
-
canParseAsync
public abstract boolean canParseAsync()Introspection method that can be used to check whether this factory can create non-blocking parsers: parsers that do not use blocking I/O abstractions but instead use aNonBlockingInputFeeder.- Returns:
- Whether this factory supports non-blocking ("async") parsing or
not (and consequently whether
createNonBlockingXxx()method(s) work)
-
getFormatReadFeatureType
Method for accessing kind ofFormatFeaturethat a parserJsonParserproduced by this factory would accept, if any;nullreturned if none.- Returns:
- Type of format-specific stream read features, if any;
nullif none
-
getFormatWriteFeatureType
Method for accessing kind ofFormatFeaturethat a parserJsonGeneratorproduced by this factory would accept, if any;nullreturned if none.- Returns:
- Type of format-specific stream read features, if any;
nullif none
-
canUseSchema
Method that can be used to quickly check whether given schema is something that parsers and/or generators constructed by this factory could use. Note that this means possible use, at the level of data format (i.e. schema is for same data format as parsers and generators this factory constructs); individual schema instances may have further usage restrictions.- Parameters:
schema- Schema instance to check- Returns:
- Whether parsers and generators constructed by this factory can use specified format schema instance
-
getFormatName
Method that returns short textual id identifying format this factory supports.- Returns:
- Name of the format handled by parsers, generators this factory creates
-
version
Description copied from interface:VersionedMethod called to detect version of the component that implements this interface; returned version should never be null, but may return specific "not available" instance (seeVersionfor details). -
isEnabled
Checked whether specified parser feature is enabled.- Parameters:
f- Feature to check- Returns:
Trueif feature is enabled;falseotherwise
-
isEnabled
Checked whether specified parser feature is enabled.- Parameters:
f- Feature to check- Returns:
Trueif feature is enabled;falseotherwise
-
isEnabled
Checked whether specified parser feature is enabled.- Parameters:
f- Feature to check- Returns:
Trueif feature is enabled;falseotherwise
-
getFactoryFeatures
public final int getFactoryFeatures() -
getStreamReadFeatures
public final int getStreamReadFeatures() -
getStreamWriteFeatures
public final int getStreamWriteFeatures() -
getFormatReadFeatures
public int getFormatReadFeatures() -
getFormatWriteFeatures
public int getFormatWriteFeatures() -
streamReadConstraints
-
streamWriteConstraints
-
errorReportConfiguration
-
constructNameMatcher
Factory method for constructing case-sensitivePropertyNameMatcherfor given names. It will callString.intern()on names unless specified that this has already been done by caller.- Parameters:
matches- Names to match, including both primary names and possible aliasesalreadyInterned- Whether name Strings are alreadyString.intern()edor not- Returns:
- Case-sensitive
PropertyNameMatcherinstance to use
-
constructCINameMatcher
public PropertyNameMatcher constructCINameMatcher(List<Named> matches, boolean alreadyInterned, Locale locale) Factory method for constructing case-insensitivePropertyNameMatcherfor given names. It will callString.intern()on names unless specified that this has already been done by caller.- Parameters:
matches- Names to match, including both primary names and possible aliasesalreadyInterned- Whether name Strings are alreadyString.intern()edor notlocale- Locale to use for case-handling- Returns:
- Case-insensitive
PropertyNameMatcherinstance to use
-
createParser
Method for constructing parser instance to decode contents of specified file.Encoding is auto-detected from contents according to JSON specification recommended mechanism. Json specification supports only UTF-8, UTF-16 and UTF-32 as valid encodings, so auto-detection implemented only for this charsets. For other charsets use
createParser(java.io.Reader).Underlying input stream (needed for reading contents) will be owned (and managed, i.e. closed as need be) by the parser, since caller has no access to it.
- Parameters:
readCtxt- Object read context to usef- File that contains content to parse- Returns:
- Parser constructed
- Throws:
JacksonException- If parser construction or initialization fails
-
createParser
Method for constructing parser instance to decode contents of specified path.Encoding is auto-detected from contents according to JSON specification recommended mechanism. Json specification supports only UTF-8, UTF-16 and UTF-32 as valid encodings, so auto-detection implemented only for this charsets. For other charsets use
createParser(java.io.Reader).Underlying input stream (needed for reading contents) will be owned (and managed, i.e. closed as need be) by the parser, since caller has no access to it.
- Parameters:
readCtxt- Object read context to usep- Path that contains content to parse- Returns:
- Parser constructed
- Throws:
JacksonException- If parser construction or initialization fails- Since:
- 3.0
-
createParser
public abstract JsonParser createParser(ObjectReadContext readCtxt, InputStream in) throws JacksonException Method for constructing JSON parser instance to parse the contents accessed via specified input stream.The input stream will not be owned by the parser, it will still be managed (i.e. closed if end-of-stream is reacher, or parser close method called) if (and only if)
StreamReadFeature.AUTO_CLOSE_SOURCEis enabled.Note: no encoding argument is taken since it can always be auto-detected as suggested by JSON RFC. Json specification supports only UTF-8, UTF-16 and UTF-32 as valid encodings, so auto-detection implemented only for this charsets. For other charsets use
createParser(java.io.Reader).- Parameters:
readCtxt- Object read context to usein- InputStream to use for reading content to parse- Returns:
- Parser constructed
- Throws:
JacksonException- If parser construction or initialization fails
-
createParser
public abstract JsonParser createParser(ObjectReadContext readCtxt, Reader r) throws JacksonException Method for constructing parser for parsing the contents accessed via specified Reader.The read stream will not be owned by the parser, it will still be managed (i.e. closed if end-of-stream is reacher, or parser close method called) if (and only if)
StreamReadFeature.AUTO_CLOSE_SOURCEis enabled.- Parameters:
readCtxt- Object read context to user- Reader to use for reading content to parse- Returns:
- Parser constructed
- Throws:
JacksonException- If parser construction or initialization fails
-
createParser
Method for constructing parser for parsing the contents of given byte array.- Parameters:
readCtxt- Object read context to usedata- Content to read- Returns:
- Parser constructed
- Throws:
JacksonException- If parser construction or initialization fails
-
createParser
public abstract JsonParser createParser(ObjectReadContext readCtxt, byte[] content, int offset, int len) throws JacksonException Method for constructing parser for parsing the contents of given byte array.- Parameters:
readCtxt- Object read context to usecontent- Buffer that contains data to parseoffset- Offset of the first data byte within bufferlen- Length of contents to parse within buffer- Returns:
- Parser constructed
- Throws:
JacksonException- If parser construction or initialization fails
-
createParser
public abstract JsonParser createParser(ObjectReadContext readCtxt, String content) throws JacksonException Method for constructing parser for parsing contents of given String.- Parameters:
readCtxt- Object read context to usecontent- Content to read- Returns:
- Parser constructed
- Throws:
JacksonException- If parser construction or initialization fails
-
createParser
Method for constructing parser for parsing contents of given char array.- Parameters:
readCtxt- Object read context to usecontent- Content to read- Returns:
- Parser constructed
- Throws:
JacksonException- If parser construction or initialization fails
-
createParser
public abstract JsonParser createParser(ObjectReadContext readCtxt, char[] content, int offset, int len) throws JacksonException Method for constructing parser for parsing contents of given char array.- Parameters:
readCtxt- Object read context to usecontent- Buffer that contains data to parseoffset- Offset of the first data byte within bufferlen- Length of contents to parse within buffer- Returns:
- Parser constructed
- Throws:
JacksonException- If parser construction or initialization fails
-
createParser
Deprecated.Since 3.0 usecreateParser(ObjectReadContext,java.io.File)- Parameters:
f- File that contains content to parse- Returns:
- Parser constructed
- Throws:
JacksonException- If parser construction or initialization fails
-
createParser
Deprecated.Since 3.0 usecreateParser(ObjectReadContext,java.io.InputStream)- Parameters:
in- InputStream to use for reading content to parse- Returns:
- Parser constructed
- Throws:
JacksonException- If parser construction or initialization fails
-
createParser
Deprecated.Since 3.0 usecreateParser(ObjectReadContext,java.io.Reader)- Parameters:
r- Reader to use for reading content to parse- Returns:
- Parser constructed
- Throws:
JacksonException- If parser construction or initialization fails
-
createParser
Deprecated.Since 3.0 usecreateParser(ObjectReadContext,byte[])- Parameters:
content- Buffer that contains content to parse- Returns:
- Parser constructed
- Throws:
JacksonException- If parser construction or initialization fails
-
createParser
@Deprecated public JsonParser createParser(byte[] content, int offset, int len) throws JacksonException Deprecated.Since 3.0 usecreateParser(ObjectReadContext,byte[],int,int)- Parameters:
content- Buffer that contains content to parseoffset- Offset of the first data byte within bufferlen- Length of contents to parse within buffer- Returns:
- Parser constructed
- Throws:
JacksonException- If parser construction or initialization fails
-
createParser
Deprecated.Since 3.0 usecreateParser(ObjectReadContext,String)- Parameters:
content- Content to parse- Returns:
- Parser constructed
- Throws:
JacksonException- If parser construction or initialization fails
-
createParser
Deprecated.Since 3.0 usecreateParser(ObjectReadContext,char[])- Parameters:
content- Buffer that contains data to parse- Returns:
- Parser constructed
- Throws:
JacksonException- If parser construction or initialization fails
-
createParser
@Deprecated public JsonParser createParser(char[] content, int offset, int len) throws JacksonException Deprecated.Since 3.0 usecreateParser(ObjectReadContext,char[],int,int)- Parameters:
content- Buffer that contains data to parseoffset- Offset of the first data byte within bufferlen- Length of contents to parse within buffer- Returns:
- Parser constructed
- Throws:
JacksonException- If parser construction or initialization fails
-
createParser
public abstract JsonParser createParser(ObjectReadContext readCtxt, DataInput in) throws JacksonException Optional method for constructing parser for reading contents from specifiedDataInputinstance.If this factory does not support
DataInputas source, will throwUnsupportedOperationException- Parameters:
readCtxt- Object read context to usein- InputStream to use for reading content to parse- Returns:
- Parser constructed
- Throws:
JacksonException- If parser construction or initialization fails
-
createNonBlockingByteArrayParser
public <P extends JsonParser & ByteArrayFeeder> P createNonBlockingByteArrayParser(ObjectReadContext readCtxt) throws JacksonException Optional method for constructing parser for non-blocking parsing viaByteArrayFeederinterface (accessed usingJsonParser.nonBlockingInputFeeder()from constructed instance).If this factory does not support non-blocking parsing (either at all, or from byte array), will throw
UnsupportedOperationException.Note that JSON-backed factory only supports parsing of UTF-8 encoded JSON content (and US-ASCII since it is proper subset); other encodings are not supported at this point.
- Type Parameters:
P- Nominal type of parser constructed and returned- Parameters:
readCtxt- Object read context to use- Returns:
- Non-blocking parser constructed
- Throws:
JacksonException- If parser construction or initialization fails
-
createNonBlockingByteBufferParser
public <P extends JsonParser & ByteArrayFeeder> P createNonBlockingByteBufferParser(ObjectReadContext readCtxt) throws JacksonException Optional method for constructing parser for non-blocking parsing viaByteBufferFeederinterface (accessed usingJsonParser.nonBlockingInputFeeder()from constructed instance).If this factory does not support non-blocking parsing (either at all, or from byte array), will throw
UnsupportedOperationException.Note that JSON-backed factory only supports parsing of UTF-8 encoded JSON content (and US-ASCII since it is proper subset); other encodings are not supported at this point.
- Type Parameters:
P- Nominal type of parser constructed and returned- Parameters:
readCtxt- Object read context to use- Returns:
- Non-blocking parser constructed
- Throws:
JacksonException- If parser construction or initialization fails
-
createGenerator
public JsonGenerator createGenerator(ObjectWriteContext writeCtxt, OutputStream out) throws JacksonException Method for constructing generator that writes contents using specifiedOutputStream. Textual encoding used will be UTF-8, where applicable.Underlying stream is NOT owned by the generator constructed, so that generator will NOT close the output stream when
JsonGenerator.close()is called (unless auto-closing feature,StreamWriteFeature.AUTO_CLOSE_TARGETis enabled). Using application needs to close it explicitly if this is the case.- Parameters:
writeCtxt- Object-binding context where applicable; used for providing contextual configurationout- OutputStream to use for writing content- Returns:
- Generator constructed
- Throws:
JacksonException- If generator construction or initialization fails- Since:
- 3.0
-
createGenerator
public abstract JsonGenerator createGenerator(ObjectWriteContext writeCtxt, OutputStream out, JsonEncoding enc) throws JacksonException Method for constructing generator that writes contents using specifiedOutputStreamwith specified textual encoding (if applicable).Underlying stream is NOT owned by the generator constructed, so that generator will NOT close the output stream when
JsonGenerator.close()is called (unless auto-closing feature,StreamWriteFeature.AUTO_CLOSE_TARGETis enabled). Using application needs to close it explicitly if this is the case.- Parameters:
writeCtxt- Object-binding context where applicable; used for providing contextual configurationout- OutputStream to use for writing contentenc- Character set encoding to use (usuallyJsonEncoding.UTF8)- Returns:
- Generator constructed
- Throws:
JacksonException- If generator construction or initialization fails- Since:
- 3.0
-
createGenerator
public abstract JsonGenerator createGenerator(ObjectWriteContext writeCtxt, Writer w) throws JacksonException Method for constructing generator that writes contents using specifiedWriter. Textual encoding used will be UTF-8, where applicable.Underlying stream is NOT owned by the generator constructed, so that generator will NOT close the Reader when
JsonGenerator.close()is called (unless auto-closing feature,StreamWriteFeature.AUTO_CLOSE_TARGETis enabled). Using application needs to close it explicitly.- Parameters:
writeCtxt- Object-binding context where applicable; used for providing contextual configurationw- Writer to use for writing content- Returns:
- Generator constructed
- Throws:
JacksonException- If generator construction or initialization fails- Since:
- 3.0
-
createGenerator
public abstract JsonGenerator createGenerator(ObjectWriteContext writeCtxt, File f, JsonEncoding enc) throws JacksonException Method for constructing generator that writes contents to specified file, overwriting contents it might have (or creating it if such file does not yet exist).Underlying stream is owned by the generator constructed, i.e. generator will handle closing of file when
JsonGenerator.close()is called.- Parameters:
writeCtxt- Object-binding context where applicable; used for providing contextual configurationf- File to write contents toenc- Character set encoding to use (usuallyJsonEncoding.UTF8)- Returns:
- Generator constructed
- Throws:
JacksonException- If generator construction or initialization fails- Since:
- 3.0
-
createGenerator
public abstract JsonGenerator createGenerator(ObjectWriteContext writeCtxt, Path p, JsonEncoding enc) throws JacksonException Method for constructing generator that writes contents to specified path, overwriting contents it might have (or creating it if such path does not yet exist).Underlying stream is owned by the generator constructed, i.e. generator will handle closing of path when
JsonGenerator.close()is called.- Parameters:
writeCtxt- Object-binding context where applicable; used for providing contextual configurationp- Path to write contents toenc- Character set encoding to use (usuallyJsonEncoding.UTF8)- Returns:
- Generator constructed
- Throws:
JacksonException- If generator construction or initialization fails- Since:
- 3.0
-
createGenerator
public JsonGenerator createGenerator(ObjectWriteContext writeCtxt, DataOutput out) throws JacksonException Method for constructing generator that writes content into specifiedDataOutput, using UTF-8 encoding (with formats where encoding is user-configurable).- Parameters:
writeCtxt- Object-binding context where applicable; used for providing contextual configurationout-DataOutputused as target of generation- Returns:
- Generator constructed
- Throws:
JacksonException- If generator construction or initialization fails- Since:
- 3.0
-
createGenerator
@Deprecated public JsonGenerator createGenerator(OutputStream out, JsonEncoding enc) throws JacksonException Deprecated.Method for constructing JSON generator for writing content using specified output stream. Encoding to use must be specified, and needs to be one of available types (as per JSON specification).Underlying stream is NOT owned by the generator constructed, so that generator will NOT close the output stream when
JsonGenerator.close()is called (unless auto-closing feature,StreamWriteFeature.AUTO_CLOSE_TARGETis enabled). Using application needs to close it explicitly if this is the case.Note: there are formats that use fixed encoding (like most binary data formats) and that ignore passed in encoding.
- Parameters:
out- OutputStream to use for writing contentenc- Character encoding to use- Returns:
- Generator constructed
- Throws:
JacksonException- If generator construction or initialization fails
-
createGenerator
Deprecated.Convenience method for constructing generator that uses default encoding of the format (UTF-8 for JSON and most other data formats),- Parameters:
out- OutputStream to use for writing content- Returns:
- Generator constructed
- Throws:
JacksonException- If generator construction or initialization fails
-
createGenerator
Deprecated.Method for constructing JSON generator for writing content using specified Writer.Underlying stream is NOT owned by the generator constructed, so that generator will NOT close the Reader when
JsonGenerator.close()is called (unless auto-closing feature,StreamWriteFeature.AUTO_CLOSE_TARGETis enabled). Using application needs to close it explicitly.- Parameters:
w- Writer to use for writing content- Returns:
- Generator constructed
- Throws:
JacksonException- If generator construction or initialization fails
-
_getBufferRecycler
Method used by factory to create buffer recycler instances for parsers and generators.Note: only public to give access for
ObjectMapper- Returns:
- BufferRecycler instance to use
-
_getRecyclerPool
Accessor for getting access toRecyclerPoolfor gettingBufferRecyclerinstance to use.- Returns:
- RecyclerPool configured for (and used by) this factory.
-
_createContext
Overridable factory method that actually instantiates desired context object.- Parameters:
contentRef- Source reference to use (relevant toTokenStreamLocationconstruction)resourceManaged- Whether input/output buffers used are managed by this factory- Returns:
- Context constructed
-
_createContext
protected IOContext _createContext(ContentReference contentRef, boolean resourceManaged, JsonEncoding enc) Overridable factory method that actually instantiates desired context object.- Parameters:
contentRef- Source reference to use (relevant toTokenStreamLocationconstruction)resourceManaged- Whether input/output buffers used are managed by this factoryenc- Character encoding defined to be used/expected- Returns:
- Context constructed
-
_createContentReference
Overridable factory method for constructingContentReferenceto pass to parser or generator being created; used in cases where no offset or length is applicable (either irrelevant, or full contents assumed).- Parameters:
contentRef- Underlying input source (parser) or target (generator)- Returns:
- InputSourceReference instance to use
-
_createContentReference
protected abstract ContentReference _createContentReference(Object contentRef, int offset, int length) Overridable factory method for constructingContentReferenceto pass to parser or generator being created; used in cases where input comes in a static buffer with relevant offset and length.- Parameters:
contentRef- Underlying input source (parser) or target (generator)offset- Offset of content in buffer (rawSource)length- Length of content in buffer (rawSource)- Returns:
- InputSourceReference instance to use
-
_createDataOutputWrapper
-
_optimizedStreamFromURL
Deprecated.Since 3.0Helper method used for constructing an optimal stream for parsers to use, when input is to be read from an URL. This helps when reading file content via URL.- Parameters:
url- Source to read content to parse from- Returns:
- InputStream constructed for given
URL - Throws:
JacksonException- If there is a problem accessing content from specifiedURL
-
_fileInputStream
Helper methods used for constructing anInputStreamfor parsers to use, when input is to be read from givenFile.- Parameters:
f- File to open stream for- Returns:
InputStreamconstructed- Throws:
JacksonException- If there is a problem opening the stream
-
_pathInputStream
- Throws:
JacksonException
-
_fileOutputStream
Helper methods used for constructing anOutputStreamfor generator to use, when target is to be written into givenFile.- Parameters:
f- File to open stream for- Returns:
OutputStreamconstructed- Throws:
JacksonException- If there is a problem opening the stream
-
_pathOutputStream
- Throws:
JacksonException
-
_checkRangeBoundsForByteArray
protected void _checkRangeBoundsForByteArray(byte[] data, int offset, int len) throws JacksonException - Throws:
JacksonException
-
_checkRangeBoundsForCharArray
protected void _checkRangeBoundsForCharArray(char[] data, int offset, int len) throws JacksonException - Throws:
JacksonException
-
_reportRangeError
- Throws:
JacksonException
-
_wrapIOFailure
-
_unsupported
protected <T> T _unsupported() -
_unsupported
-