Class SmileFactory
- All Implemented Interfaces:
Versioned
SmileParser and SmileGenerator
instances; both of which handle
Smile encoded data.
Extends JsonFactory mostly so that users can actually use it in place
of regular non-Smile factory instances.
Note on using non-byte-based sources/targets (char based, like
Reader and Writer): these can not be
used for Smile-format documents, and thus will either downgrade to
textual JSON (when parsing), or throw exception (when trying to create
generator).
- Since:
- 1.6
- Author:
- tatu
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected booleanWhether non-supported methods (ones trying to output using char-based targets likeWriter, for example) should be delegated to regular Jackson JSON processing (if set to true); or throwUnsupportedOperationException(if set to false)protected intprotected intstatic final StringName used to identify Smile format.Fields inherited from class JsonFactory
_characterEscapes, _generatorFeatures, _inputDecorator, _objectCodec, _outputDecorator, _parserFeatures, _recyclerRef, _rootByteSymbols, _rootCharSymbols, FORMAT_NAME_JSON -
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor used to create factory instances. -
Method Summary
Modifier and TypeMethodDescriptionprotected SmileGenerator_createJsonGenerator(OutputStream out, IOContext ctxt) protected JsonGenerator_createJsonGenerator(Writer out, IOContext ctxt) Overridable factory method that actually instantiates desired generator.protected SmileParser_createJsonParser(byte[] data, int offset, int len, IOContext ctxt) Overridable factory method that actually instantiates desired parser.protected SmileParser_createJsonParser(InputStream in, IOContext ctxt) Overridable factory method that actually instantiates desired parser.protected JsonParser_createJsonParser(Reader r, IOContext ctxt) Overridable factory method that actually instantiates desired parser.protected Writer_createWriter(OutputStream out, JsonEncoding enc, IOContext ctxt) final SmileFactoryconfigure(SmileGenerator.Feature f, boolean state) Method for enabling or disabling specified generator feature (checkJsonGenerator.Featurefor list of features)final SmileFactoryconfigure(SmileParser.Feature f, boolean state) Method for enabling or disabling specified parser feature (checkSmileParser.Featurefor list of features)Since Smile format always uses UTF-8 internally, no encoding need to be passed to this method.createJsonGenerator(OutputStream out, JsonEncoding enc) note: co-variant return typecreateJsonParser(byte[] data) Method for constructing parser for parsing the contents of given byte array.createJsonParser(byte[] data, int offset, int len) Method for constructing parser for parsing the contents of given byte array.Method for constructing JSON parser instance to parse contents of specified file.Method for constructing JSON parser instance to parse the contents accessed via specified input stream.createJsonParser(URL url) Method for constructing JSON parser instance to parse contents of resource reference by given URL.voiddelegateToTextual(boolean state) Method for disabling specified generator feature (checkJsonGenerator.Featurefor list of features)Method for disabling specified parser features (checkSmileParser.Featurefor list of features)Method for enabling specified generator features (checkJsonGenerator.Featurefor list of features)Method for enabling specified parser feature (checkSmileParser.Featurefor list of features)Method that returns short textual id identifying format this factory supports.hasFormat(InputAccessor acc) Sub-classes need to override this method (as of 1.8)final booleanCheck whether specified generator feature is enabled.final booleanChecked whether specified parser feature is enabled.Methods inherited from class JsonFactory
_createContext, _createUTF8JsonGenerator, _getBufferRecycler, _optimizedStreamFromURL, configure, configure, createJsonGenerator, createJsonGenerator, createJsonParser, createJsonParser, disable, disable, disableGeneratorFeature, disableParserFeature, enable, enable, enableGeneratorFeature, enableParserFeature, getCharacterEscapes, getCodec, getInputDecorator, getOutputDecorator, hasJSONFormat, isEnabled, isEnabled, isGeneratorFeatureEnabled, isParserFeatureEnabled, setCharacterEscapes, setCodec, setGeneratorFeature, setInputDecorator, setOutputDecorator, setParserFeature, version
-
Field Details
-
FORMAT_NAME_SMILE
Name used to identify Smile format. (and returned bygetFormatName()- See Also:
-
_cfgDelegateToTextual
protected boolean _cfgDelegateToTextualWhether non-supported methods (ones trying to output using char-based targets likeWriter, for example) should be delegated to regular Jackson JSON processing (if set to true); or throwUnsupportedOperationException(if set to false) -
_smileParserFeatures
protected int _smileParserFeatures -
_smileGeneratorFeatures
protected int _smileGeneratorFeatures
-
-
Constructor Details
-
SmileFactory
public SmileFactory()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. -
SmileFactory
-
-
Method Details
-
delegateToTextual
public void delegateToTextual(boolean state) -
getFormatName
Description copied from class:JsonFactoryMethod that returns short textual id identifying format this factory supports.Note: sub-classes should override this method; default implementation will return null for all sub-classes
- Overrides:
getFormatNamein classJsonFactory
-
hasFormat
Sub-classes need to override this method (as of 1.8)- Overrides:
hasFormatin classJsonFactory- Throws:
IOException
-
configure
Method for enabling or disabling specified parser feature (checkSmileParser.Featurefor list of features) -
enable
Method for enabling specified parser feature (checkSmileParser.Featurefor list of features) -
disable
Method for disabling specified parser features (checkSmileParser.Featurefor list of features) -
isEnabled
Checked whether specified parser feature is enabled. -
configure
Method for enabling or disabling specified generator feature (checkJsonGenerator.Featurefor list of features)- Since:
- 1.2
-
enable
Method for enabling specified generator features (checkJsonGenerator.Featurefor list of features) -
disable
Method for disabling specified generator feature (checkJsonGenerator.Featurefor list of features) -
isEnabled
Check whether specified generator feature is enabled. -
createJsonParser
Description copied from class:JsonFactoryMethod for constructing JSON parser instance to parse contents of specified file. Encoding is auto-detected from contents according to JSON specification recommended mechanism.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.
- Overrides:
createJsonParserin classJsonFactory- Parameters:
f- File that contains JSON content to parse- Throws:
IOExceptionJsonParseException
-
createJsonParser
Description copied from class:JsonFactoryMethod for constructing JSON parser instance to parse contents of resource reference by given URL. Encoding is auto-detected from contents according to JSON specification recommended mechanism.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.
- Overrides:
createJsonParserin classJsonFactory- Parameters:
url- URL pointing to resource that contains JSON content to parse- Throws:
IOExceptionJsonParseException
-
createJsonParser
Description copied from class:JsonFactoryMethod 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)
JsonParser.Feature.AUTO_CLOSE_SOURCEis enabled.Note: no encoding argument is taken since it can always be auto-detected as suggested by Json RFC.
- Overrides:
createJsonParserin classJsonFactory- Parameters:
in- InputStream to use for reading JSON content to parse- Throws:
IOExceptionJsonParseException
-
createJsonParser
Description copied from class:JsonFactoryMethod for constructing parser for parsing the contents of given byte array.- Overrides:
createJsonParserin classJsonFactory- Throws:
IOExceptionJsonParseException
-
createJsonParser
public SmileParser createJsonParser(byte[] data, int offset, int len) throws IOException, JsonParseException Description copied from class:JsonFactoryMethod for constructing parser for parsing the contents of given byte array.- Overrides:
createJsonParserin classJsonFactory- Parameters:
data- Buffer that contains data to parseoffset- Offset of the first data byte within bufferlen- Length of contents to parse within buffer- Throws:
IOExceptionJsonParseException
-
createJsonGenerator
note: co-variant return type
- Overrides:
createJsonGeneratorin classJsonFactory- Parameters:
out- OutputStream to use for writing JSON contentenc- Character encoding to use- Throws:
IOException
-
createJsonGenerator
Since Smile format always uses UTF-8 internally, no encoding need to be passed to this method.- Overrides:
createJsonGeneratorin classJsonFactory- Throws:
IOException
-
_createJsonParser
protected SmileParser _createJsonParser(InputStream in, IOContext ctxt) throws IOException, JsonParseException Overridable factory method that actually instantiates desired parser.- Overrides:
_createJsonParserin classJsonFactory- Throws:
IOExceptionJsonParseException
-
_createJsonParser
protected JsonParser _createJsonParser(Reader r, IOContext ctxt) throws IOException, JsonParseException Overridable factory method that actually instantiates desired parser.- Overrides:
_createJsonParserin classJsonFactory- Throws:
IOExceptionJsonParseException
-
_createJsonParser
protected SmileParser _createJsonParser(byte[] data, int offset, int len, IOContext ctxt) throws IOException, JsonParseException Overridable factory method that actually instantiates desired parser.- Overrides:
_createJsonParserin classJsonFactory- Throws:
IOExceptionJsonParseException
-
_createJsonGenerator
Overridable factory method that actually instantiates desired generator.- Overrides:
_createJsonGeneratorin classJsonFactory- Throws:
IOException
-
_createWriter
protected Writer _createWriter(OutputStream out, JsonEncoding enc, IOContext ctxt) throws IOException - Overrides:
_createWriterin classJsonFactory- Throws:
IOException
-
_createJsonGenerator
- Throws:
IOException
-