Top Description Inners Fields Constructors Methods
tools.jackson.core

public abstract Class TokenStreamFactory

extends Object
implements Versioned, Serializable, Snapshottable<TokenStreamFactory>
Class Inheritance
All Implemented Interfaces
tools.jackson.core.util.Snapshottable, java.io.Serializable, tools.jackson.core.Versioned
Known Direct Subclasses
tools.jackson.core.base.DecorableTSFactory
Imports
java.io.*, java.net.URL, java.nio.file.Files, .Path, java.util.List, .Locale, .Objects, tools.jackson.core.async.ByteArrayFeeder, tools.jackson.core.exc.JacksonIOException, .StreamReadException, tools.jackson.core.io.*, tools.jackson.core.json.JsonFactory, tools.jackson.core.sym.PropertyNameMatcher, .SimpleNameMatcher, tools.jackson.core.util.BufferRecycler, .JacksonFeature, .JsonRecyclerPools, .Named, .RecyclerPool, .Snapshottable

The main factory class of Jackson streaming package, used to configure and construct token reader (aka parser, 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)

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static enum
TokenStreamFactory.Feature

Enumeration that defines all on/off features that can only be changed for TokenStreamFactory.

Field Summary

Modifier and TypeField and Description
protected final ErrorReportConfiguration
_errorReportConfiguration

Active ErrorReportConfiguration to use.

protected final int
_factoryFeatures

Currently enabled TokenStreamFactory.Features features as a bitmask.

protected final int
_formatReadFeatures

Set of format-specific read features enabled, as bitmask.

protected final int
_formatWriteFeatures

Set of format-specific write features enabled, as bitmask.

protected final RecyclerPool<BufferRecycler>
protected final StreamReadConstraints
_streamReadConstraints

Active StreamReadConstraints to use.

protected final int
_streamReadFeatures

Currently enabled StreamReadFeatures as a bitmask.

protected final StreamWriteConstraints
_streamWriteConstraints

Active StreamWriteConstraints to use.

protected final int
_streamWriteFeatures

Currently enabled StreamWriteFeatures as a bitmask.

protected static final int
DEFAULT_FACTORY_FEATURE_FLAGS

Bitfield (set of flags) of all factory features that are enabled by default.

protected static final int
DEFAULT_STREAM_READ_FEATURE_FLAGS

Bitfield (set of flags) of all parser features that are enabled by default.

protected static final int
DEFAULT_STREAM_WRITE_FEATURE_FLAGS

Bitfield (set of flags) of all generator features that are enabled by default.

public static final ObjectWriteContext
EMPTY_WRITE_CONTEXT

Shareable stateles "empty" ObjectWriteContext Object, passed in cases where caller had not passed actual context - "null object" of sort.

private static final long

Constructor Summary

AccessConstructor and Description
protected
TokenStreamFactory(StreamReadConstraints
StreamReadConstraints to use with parsers factory creates
src
,
StreamWriteConstraints
StreamWriteConstraints to use with generators factory creates
swc
,
ErrorReportConfiguration
ErrorReportConfiguration to use with parsers factory creates
erc
,
int
Bitmask of format-specific read features enabled
formatReadFeatures
,
int
Bitmask of format-specific write features enabled
formatWriteFeatures
)

Default constructor used to create factory instances.

protected
TokenStreamFactory(TSFBuilder<?, ?>
Builder with configuration to use
baseBuilder
)

Constructors used by TSFBuilder for instantiation.

protected
TokenStreamFactory(TokenStreamFactory
Source factory with configuration to copy
src
)

Constructor used if a snapshot is created, or possibly for sub-classing or wrapping (delegating)

Method Summary

Modifier and TypeMethod and Description
protected void
_checkRangeBoundsForByteArray(byte[] data, int offset, int len)

protected void
_checkRangeBoundsForCharArray(char[] data, int offset, int len)

protected abstract ContentReference

Returns:

InputSourceReference instance to use
_createContentReference
(Object
Underlying input source (parser) or target (generator)
contentRef
)

Overridable factory method for constructing ContentReference to 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

Returns:

InputSourceReference instance to use
_createContentReference
(Object
Underlying input source (parser) or target (generator)
contentRef
,
int
Offset of content in buffer (rawSource)
offset
,
int
Length of content in buffer (rawSource)
length
)

Overridable factory method for constructing ContentReference to pass to parser or generator being created; used in cases where input comes in a static buffer with relevant offset and length.

protected IOContext

Returns:

Context constructed
_createContext
(ContentReference
Source reference to use (relevant to TokenStreamLocation construction)
contentRef
,
boolean
Whether input/output buffers used are managed by this factory
resourceManaged
)

Overridable factory method that actually instantiates desired context object.

protected IOContext

Returns:

Context constructed
_createContext
(ContentReference
Source reference to use (relevant to TokenStreamLocation construction)
contentRef
,
boolean
Whether input/output buffers used are managed by this factory
resourceManaged
,
JsonEncoding
Character encoding defined to be used/expected
enc
)

Overridable factory method that actually instantiates desired context object.

protected OutputStream
protected InputStream

Returns:

InputStream constructed
_fileInputStream
(File
File to open stream for
f
)

Helper methods used for constructing an InputStream for parsers to use, when input is to be read from given File.

protected OutputStream

Returns:

OutputStream constructed
_fileOutputStream
(File
File to open stream for
f
)

Helper methods used for constructing an OutputStream for generator to use, when target is to be written into given File.

public BufferRecycler

Returns:

BufferRecycler instance to use
_getBufferRecycler
()

Method used by factory to create buffer recycler instances for parsers and generators.

public RecyclerPool<BufferRecycler>

Returns:

RecyclerPool configured for (and used by) this factory.
_getRecyclerPool
()

Accessor for getting access to RecyclerPool for getting BufferRecycler instance to use.

protected InputStream

Returns:

InputStream constructed for given URL
_optimizedStreamFromURL
(URL
Source to read content to parse from
url
)
Deprecated Since 3.0

Helper method used for constructing an optimal stream for parsers to use, when input is to be read from an URL.

protected InputStream
protected OutputStream
protected <T> T
protected <T> T
protected <T> T
_unsupported(String str, Object... args)

protected JacksonException
public abstract boolean

Returns:

Whether format supported by this factory supports native binary content
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.

public abstract boolean

Returns:

Whether this factory supports non-blocking ("async") parsing or not (and consequently whether createNonBlockingXxx() method(s) work)
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 a tools.jackson.core.async.NonBlockingInputFeeder.

public abstract boolean

Returns:

Whether parsers and generators constructed by this factory can use specified format schema instance
canUseSchema
(FormatSchema
Schema instance to check
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.

public PropertyNameMatcher

Returns:

Case-insensitive PropertyNameMatcher instance to use
constructCINameMatcher
(List<Named>
Names to match, including both primary names and possible aliases
matches
,
boolean
Whether name Strings are already String.intern()ed or not
alreadyInterned
,
Locale
Locale to use for case-handling
locale
)

Factory method for constructing case-insensitive PropertyNameMatcher for given names.

public PropertyNameMatcher

Returns:

Case-sensitive PropertyNameMatcher instance to use
constructNameMatcher
(List<Named>
Names to match, including both primary names and possible aliases
matches
,
boolean
Whether name Strings are already String.intern()ed or not
alreadyInterned
)

Factory method for constructing case-sensitive PropertyNameMatcher for given names.

public abstract TokenStreamFactory

Returns:

Newly constructed stream factory instance of same type as this one, with identical configuration settings
copy
()

Method similar to snapshot(), 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.

public JsonGenerator

Returns:

Generator constructed
createGenerator
(ObjectWriteContext
Object-binding context where applicable; used for providing contextual configuration
writeCtxt
,
OutputStream
OutputStream to use for writing content
out
)

Method for constructing generator that writes contents using specified OutputStream.

public abstract JsonGenerator

Returns:

Generator constructed
createGenerator
(ObjectWriteContext
Object-binding context where applicable; used for providing contextual configuration
writeCtxt
,
OutputStream
OutputStream to use for writing content
out
,
JsonEncoding
Character set encoding to use (usually JsonEncoding#UTF8)
enc
)

Method for constructing generator that writes contents using specified OutputStream with specified textual encoding (if applicable).

public abstract JsonGenerator

Returns:

Generator constructed
createGenerator
(ObjectWriteContext
Object-binding context where applicable; used for providing contextual configuration
writeCtxt
,
Writer
Writer to use for writing content
w
)

Method for constructing generator that writes contents using specified Writer.

public abstract JsonGenerator

Returns:

Generator constructed
createGenerator
(ObjectWriteContext
Object-binding context where applicable; used for providing contextual configuration
writeCtxt
,
File
File to write contents to
f
,
JsonEncoding
Character set encoding to use (usually JsonEncoding#UTF8)
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).

public abstract JsonGenerator

Returns:

Generator constructed
createGenerator
(ObjectWriteContext
Object-binding context where applicable; used for providing contextual configuration
writeCtxt
,
Path
Path to write contents to
p
,
JsonEncoding
Character set encoding to use (usually JsonEncoding#UTF8)
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).

public JsonGenerator

Returns:

Generator constructed
createGenerator
(ObjectWriteContext
Object-binding context where applicable; used for providing contextual configuration
writeCtxt
,
DataOutput
DataOutput used as target of generation
out
)

Method for constructing generator that writes content into specified DataOutput, using UTF-8 encoding (with formats where encoding is user-configurable).

public JsonGenerator

Returns:

Generator constructed
createGenerator
(OutputStream
OutputStream to use for writing content
out
,
JsonEncoding
Character encoding to use
enc
)
Deprecated

Method for constructing JSON generator for writing content using specified output stream.

public JsonGenerator

Returns:

Generator constructed
createGenerator
(OutputStream
OutputStream to use for writing content
out
)
Deprecated

Convenience method for constructing generator that uses default encoding of the format (UTF-8 for JSON and most other data formats),

public JsonGenerator

Returns:

Generator constructed
createGenerator
(Writer
Writer to use for writing content
w
)
Deprecated

Method for constructing JSON generator for writing content using specified Writer.

public <
Nominal type of parser constructed and returned
P extends JsonParser & ByteArrayFeeder
>
P

Returns:

Non-blocking parser constructed
createNonBlockingByteArrayParser
(ObjectReadContext
Object read context to use
readCtxt
)

Optional method for constructing parser for non-blocking parsing via tools.jackson.core.async.ByteArrayFeeder interface (accessed using JsonParser#nonBlockingInputFeeder() from constructed instance).

public <
Nominal type of parser constructed and returned
P extends JsonParser & ByteArrayFeeder
>
P

Returns:

Non-blocking parser constructed
createNonBlockingByteBufferParser
(ObjectReadContext
Object read context to use
readCtxt
)

Optional method for constructing parser for non-blocking parsing via tools.jackson.core.async.ByteBufferFeeder interface (accessed using JsonParser#nonBlockingInputFeeder() from constructed instance).

public abstract JsonParser

Returns:

Parser constructed
createParser
(ObjectReadContext
Object read context to use
readCtxt
,
File
File that contains content to parse
f
)

Method for constructing parser instance to decode contents of specified file.

public abstract JsonParser

Returns:

Parser constructed
createParser
(ObjectReadContext
Object read context to use
readCtxt
,
Path
Path that contains content to parse
p
)

Method for constructing parser instance to decode contents of specified path.

public abstract JsonParser

Returns:

Parser constructed
createParser
(ObjectReadContext
Object read context to use
readCtxt
,
InputStream
InputStream to use for reading content to parse
in
)

Method for constructing JSON parser instance to parse the contents accessed via specified input stream.

public abstract JsonParser

Returns:

Parser constructed
createParser
(ObjectReadContext
Object read context to use
readCtxt
,
Reader
Reader to use for reading content to parse
r
)

Method for constructing parser for parsing the contents accessed via specified Reader.

public JsonParser

Returns:

Parser constructed
createParser
(ObjectReadContext
Object read context to use
readCtxt
,
byte[]
Content to read
data
)

Method for constructing parser for parsing the contents of given byte array.

public abstract JsonParser

Returns:

Parser constructed
createParser
(ObjectReadContext
Object read context to use
readCtxt
,
byte[]
Buffer that contains data to parse
content
,
int
Offset of the first data byte within buffer
offset
,
int
Length of contents to parse within buffer
len
)

Method for constructing parser for parsing the contents of given byte array.

public abstract JsonParser

Returns:

Parser constructed
createParser
(ObjectReadContext
Object read context to use
readCtxt
,
String
Content to read
content
)

Method for constructing parser for parsing contents of given String.

public JsonParser

Returns:

Parser constructed
createParser
(ObjectReadContext
Object read context to use
readCtxt
,
char[]
Content to read
content
)

Method for constructing parser for parsing contents of given char array.

public abstract JsonParser

Returns:

Parser constructed
createParser
(ObjectReadContext
Object read context to use
readCtxt
,
char[]
Buffer that contains data to parse
content
,
int
Offset of the first data byte within buffer
offset
,
int
Length of contents to parse within buffer
len
)

Method for constructing parser for parsing contents of given char array.

public JsonParser

Returns:

Parser constructed
createParser
(File
File that contains content to parse
f
)

public JsonParser

Returns:

Parser constructed
createParser
(InputStream
InputStream to use for reading content to parse
in
)

public JsonParser

Returns:

Parser constructed
createParser
(Reader
Reader to use for reading content to parse
r
)

public JsonParser

Returns:

Parser constructed
createParser
(byte[]
Buffer that contains content to parse
content
)
Deprecated Since 3.0 use createParser(ObjectReadContext, byte[])

public JsonParser

Returns:

Parser constructed
createParser
(byte[]
Buffer that contains content to parse
content
,
int
Offset of the first data byte within buffer
offset
,
int
Length of contents to parse within buffer
len
)

public JsonParser

Returns:

Parser constructed
createParser
(String
Content to parse
content
)
Deprecated Since 3.0 use createParser(ObjectReadContext, String)

public JsonParser

Returns:

Parser constructed
createParser
(char[]
Buffer that contains data to parse
content
)
Deprecated Since 3.0 use createParser(ObjectReadContext, char[])

public JsonParser

Returns:

Parser constructed
createParser
(char[]
Buffer that contains data to parse
content
,
int
Offset of the first data byte within buffer
offset
,
int
Length of contents to parse within buffer
len
)

public abstract JsonParser

Returns:

Parser constructed
createParser
(ObjectReadContext
Object read context to use
readCtxt
,
DataInput
InputStream to use for reading content to parse
in
)

Optional method for constructing parser for reading contents from specified DataInput instance.

public ErrorReportConfiguration
public final int
public abstract String

Returns:

Name of the format handled by parsers, generators this factory creates
getFormatName
()

Method that returns short textual id identifying format this factory supports.

public int
public Class<? extends FormatFeature>

Returns:

Type of format-specific stream read features, if any; null if none
getFormatReadFeatureType
()

Method for accessing kind of FormatFeature that a parser JsonParser produced by this factory would accept, if any; null returned if none.

public int
public Class<? extends FormatFeature>

Returns:

Type of format-specific stream read features, if any; null if none
getFormatWriteFeatureType
()

Method for accessing kind of FormatFeature that a parser JsonGenerator produced by this factory would accept, if any; null returned if none.

public final int
public final int
public final boolean

Returns:

True if feature is enabled; false otherwise
isEnabled
(TokenStreamFactory.Feature
Feature to check
f
)

Checked whether specified parser feature is enabled.

public final boolean

Returns:

True if feature is enabled; false otherwise
isEnabled
(StreamReadFeature
Feature to check
f
)

Checked whether specified parser feature is enabled.

public final boolean

Returns:

True if feature is enabled; false otherwise
isEnabled
(StreamWriteFeature
Feature to check
f
)

Checked whether specified parser feature is enabled.

public abstract TSFBuilder<?, ?>

Returns:

Builder instance initialized with configuration this stream factory has
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.

public boolean

Returns:

Whether format supported by this factory requires Object properties to be ordered.
requiresPropertyOrdering
()

Introspection method that higher-level functionality may call to see whether underlying data format requires a stable ordering of object properties or not.

public abstract TokenStreamFactory

Returns:

This factory instance to allow call chaining
snapshot
()

Redeclares tools.jackson.core.util.Snapshottable.snapshot.

Method for constructing a new TokenStreamFactory that has the same settings as this instance, but is otherwise independent (i.e. nothing is actually shared, symbol tables are separate).

public StreamReadConstraints
public StreamWriteConstraints
public abstract Version
version()

Redeclares tools.jackson.core.Versioned.version.

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 (see Version for details).

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait