Class SmileFactory

  • All Implemented Interfaces:
    Versioned

    public class SmileFactory
    extends JsonFactory
    Factory used for constructing 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 Detail

      • _cfgDelegateToTextual

        protected boolean _cfgDelegateToTextual
        Whether non-supported methods (ones trying to output using char-based targets like Writer, for example) should be delegated to regular Jackson JSON processing (if set to true); or throw UnsupportedOperationException (if set to false)
      • _smileParserFeatures

        protected int _smileParserFeatures
      • _smileGeneratorFeatures

        protected int _smileGeneratorFeatures
    • Constructor Detail

      • 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

        public SmileFactory​(ObjectCodec oc)
    • Method Detail

      • delegateToTextual

        public void delegateToTextual​(boolean state)
      • getFormatName

        public java.lang.String getFormatName()
        Description copied from class: JsonFactory
        Method 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:
        getFormatName in class JsonFactory
      • isEnabled

        public final boolean isEnabled​(SmileParser.Feature f)
        Checked whether specified parser feature is enabled.
      • isEnabled

        public final boolean isEnabled​(SmileGenerator.Feature f)
        Check whether specified generator feature is enabled.
      • createJsonParser

        public SmileParser createJsonParser​(java.io.File f)
                                     throws java.io.IOException,
                                            JsonParseException
        Description copied from class: JsonFactory
        Method 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:
        createJsonParser in class JsonFactory
        Parameters:
        f - File that contains JSON content to parse
        Throws:
        java.io.IOException
        JsonParseException
      • createJsonParser

        public SmileParser createJsonParser​(java.net.URL url)
                                     throws java.io.IOException,
                                            JsonParseException
        Description copied from class: JsonFactory
        Method 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:
        createJsonParser in class JsonFactory
        Parameters:
        url - URL pointing to resource that contains JSON content to parse
        Throws:
        java.io.IOException
        JsonParseException
      • createJsonParser

        public SmileParser createJsonParser​(java.io.InputStream in)
                                     throws java.io.IOException,
                                            JsonParseException
        Description copied from class: JsonFactory
        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) JsonParser.Feature.AUTO_CLOSE_SOURCE is enabled.

        Note: no encoding argument is taken since it can always be auto-detected as suggested by Json RFC.

        Overrides:
        createJsonParser in class JsonFactory
        Parameters:
        in - InputStream to use for reading JSON content to parse
        Throws:
        java.io.IOException
        JsonParseException
      • createJsonParser

        public SmileParser createJsonParser​(byte[] data,
                                            int offset,
                                            int len)
                                     throws java.io.IOException,
                                            JsonParseException
        Description copied from class: JsonFactory
        Method for constructing parser for parsing the contents of given byte array.
        Overrides:
        createJsonParser in class JsonFactory
        Parameters:
        data - Buffer that contains data to parse
        offset - Offset of the first data byte within buffer
        len - Length of contents to parse within buffer
        Throws:
        java.io.IOException
        JsonParseException
      • createJsonGenerator

        public SmileGenerator createJsonGenerator​(java.io.OutputStream out,
                                                  JsonEncoding enc)
                                           throws java.io.IOException

        note: co-variant return type

        Overrides:
        createJsonGenerator in class JsonFactory
        Parameters:
        out - OutputStream to use for writing JSON content
        enc - Character encoding to use
        Throws:
        java.io.IOException
      • createJsonGenerator

        public SmileGenerator createJsonGenerator​(java.io.OutputStream out)
                                           throws java.io.IOException
        Since Smile format always uses UTF-8 internally, no encoding need to be passed to this method.
        Overrides:
        createJsonGenerator in class JsonFactory
        Throws:
        java.io.IOException
      • _createJsonGenerator

        protected JsonGenerator _createJsonGenerator​(java.io.Writer out,
                                                     IOContext ctxt)
                                              throws java.io.IOException
        Overridable factory method that actually instantiates desired generator.
        Overrides:
        _createJsonGenerator in class JsonFactory
        Throws:
        java.io.IOException
      • _createWriter

        protected java.io.Writer _createWriter​(java.io.OutputStream out,
                                               JsonEncoding enc,
                                               IOContext ctxt)
                                        throws java.io.IOException
        Overrides:
        _createWriter in class JsonFactory
        Throws:
        java.io.IOException
      • _createJsonGenerator

        protected SmileGenerator _createJsonGenerator​(java.io.OutputStream out,
                                                      IOContext ctxt)
                                               throws java.io.IOException
        Throws:
        java.io.IOException