Top Description Inners Fields Constructors Methods
tools.jackson.dataformat.smile

public Class SmileGenerator

extends GeneratorBase
Class Inheritance
Imports
java.io.*, java.math.BigDecimal, .BigInteger, java.util.Arrays, tools.jackson.core.*, tools.jackson.core.io.*, tools.jackson.core.json.DupDetector, tools.jackson.core.util.JacksonFeatureSet, .SimpleStreamWriteContext, tools.jackson.core.base.GeneratorBase

JsonGenerator implementation for Smile-encoded content (see Smile Format Specification)

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
SmileGenerator.SharedStringNode

Helper class used for keeping track of possibly shareable String references (for property names and/or short String values)

Field Summary

Modifier and TypeField and Description
protected boolean
_bufferRecyclable

Flag that indicates whether the output buffer is recyclable (and needs to be returned to recycler once we are done) or not.

protected int
_bytesWritten

Let's keep track of how many bytes have been output, may prove useful when debugging.

protected int
_formatFeatures

Bit flag composed of bits that indicate which tools.jackson.dataformat.smile.SmileWriteFeatures are enabled.

protected final OutputStream
protected byte[]
_outputBuffer

Intermediate buffer in which contents are buffered before being written using _out.

protected final int
_outputEnd

Offset to index after the last valid index in _outputBuffer.

protected int
_outputTail

Pointer to the next available byte in _outputBuffer

protected int
_seenNameCount

Number of entries in _seenNames; -1 if no shared name detection is enabled

protected SmileGenerator.SharedStringNode[]
_seenNames

Raw data structure used for checking whether property name to write can be output using back reference or not.

protected int
_seenStringValueCount

Number of entries in _seenStringValues; -1 if no shared text value detection is enabled

protected SmileGenerator.SharedStringNode[]
_seenStringValues

Raw data structure used for checking whether String value to write can be output using back reference or not.

protected SimpleStreamWriteContext
_streamWriteContext

Object that keeps track of the current contextual state of the generator.

protected static final int
protected static final int
protected static final long
private static final int
MIN_BUFFER_LENGTH

To simplify certain operations, we require output buffer length to allow outputting of contiguous 256 character UTF-8 encoded String value.

protected static final long
protected static final int
REPLACEMENT_CHAR

The replacement character to use to fix invalid Unicode sequences (mismatched surrogate pair).

protected static final byte
protected static final byte
protected static final byte
protected static final byte
protected static final byte
protected static final byte
protected static final byte
Inherited from tools.jackson.core.base.GeneratorBase:
_closed_ioContext_objectWriteContext_streamWriteConstraints_streamWriteFeaturesDEFAULT_BINARY_WRITE_CAPABILITIESDEFAULT_TEXTUAL_WRITE_CAPABILITIESDEFAULT_WRITE_CAPABILITIESMAX_BIG_DECIMAL_SCALESURR1_FIRSTSURR1_LASTSURR2_FIRSTSURR2_LASTWRITE_BINARYWRITE_BOOLEANWRITE_NULLWRITE_NUMBERWRITE_RAWWRITE_STRING

Constructor Summary

AccessConstructor and Description
public
SmileGenerator(ObjectWriteContext writeCtxt, IOContext ioCtxt, int streamWriteFeatures, int smileFeatures, OutputStream out)

public
SmileGenerator(ObjectWriteContext writeCtxt, IOContext ioCtxt, int streamWriteFeatures, int smileFeatures, OutputStream out, byte[] outputBuffer, int offset, boolean bufferRecyclable)

Method Summary

Modifier and TypeMethod and Description
private final void
private final void
private int
_appendReplacementChar(byte[] outBuf, int outputPtr)

protected void
private int
_decodeAndWriteSurrogate(int surr1, int surr2, byte[] outBuf, int outputPtr)

private final void
private final int
private final int
protected final void
private int
_invalidSurrogateEnd(int surr1, int surr2, byte[] outBuf, int outputPtr)

private int
_invalidSurrogateStart(int code, byte[] outBuf, int outputPtr)

private void
_mediumUTF8Encode(char[] str, int inputPtr, int inputEnd)

private void
_mediumUTF8Encode(String str, int inputPtr, int inputEnd)

protected UnsupportedOperationException
private int
_readMore(InputStream in, byte[] readBuffer, int inputPtr, int inputEnd, int maxRead)

protected void
_releaseBuffers()

Implements abstract tools.jackson.core.base.GeneratorBase._releaseBuffers.

Method called to release any buffers generator may be holding, once generator is being closed.

private final int
_shortUTF8Encode(char[] str, int i, int end)

Helper method called when the whole character sequence is known to fit in the output buffer regardless of UTF-8 expansion.

private final int
_shortUTF8Encode(String str, int i, int end)

private final int
_shortUTF8Encode2(char[] str, int i, int end, int outputPtr)

Helper method called when the whole character sequence is known to fit in the output buffer, but not all characters are single-byte (ASCII) characters.

private final int
_shortUTF8Encode2(String str, int i, int end, int outputPtr)

protected StreamReadConstraints
_streamReadConstraints()

We need access to some reader-side constraints for safety-check within number decoding for {@linl #writeNumber(String)}: for now we need to rely on global defaults; should be ok for basic safeguarding.

private static final boolean
_validBackRef(int index)

Helper method used to ensure that we do not use back-reference values that would produce illegal byte sequences (ones with byte 0xFE or 0xFF).

protected final void
_verifyValueWrite(String typeMsg)

Implements abstract tools.jackson.core.base.GeneratorBase._verifyValueWrite.

Method called before trying to write a value (scalar or structured), to verify that this is legal in current output state, as well as to output separators if and as necessary.

protected void
_write7BitBinaryWithLength(byte[] data, int offset, int len)

protected int
_write7BitBinaryWithLength(InputStream in, int bytesLeft, byte[] buffer)

private final void
_writeByte(byte b)

private final void
_writeBytes(byte b1, byte b2)

private final void
_writeBytes(byte b1, byte b2, byte b3)

private final void
_writeBytes(byte b1, byte b2, byte b3, byte b4)

private final void
_writeBytes(byte b1, byte b2, byte b3, byte b4, byte b5)

private final void
_writeBytes(byte b1, byte b2, byte b3, byte b4, byte b5, byte b6)

private final void
_writeBytes(byte[] data, int offset, int len)

private final int
_writeBytes(InputStream in, int bytesLeft)

private final void
_writeBytesLong(byte[] data, int offset, int len)

protected void
protected void
_writeIntegralNumber(String enc, boolean neg)

private final void
private final void
protected final void
protected final void
private final void
_writeNonSharedString(final String text, final int len)

Helper method called to handle cases where String value to write is known to be long enough not to be shareable.

private final void
_writeNonShortFieldName(final String name, final int len)

private final int
_writeNumberNoChecks(int ptr, int i)

private final int
_writeNumberNoChecks(int ptr, long l)

private final int
_writeNumberNoChecks(int ptr, double d)

private void
_writePositiveVInt(int i)

Helper method for writing a 32-bit positive (really 31-bit then) value.

private final void
private final void
private void
_writeSignedVInt(int input)

Helper method for writing 32-bit signed value, using "zig zag encoding" (see protocol buffers for explanation -- basically, sign bit is moved as LSB, rest of value shifted left by one) coupled with basic variable length encoding

public void
assignCurrentValue(Object v)

Implements abstract tools.jackson.core.JsonGenerator.assignCurrentValue.

Helper method, usually equivalent to: getOutputContext().assignCurrentValue(v); used to assign "current value" for the current context of this generator.

public SmileGenerator
configure(SmileWriteFeature f, boolean state)

public Object
currentValue()

Implements abstract tools.jackson.core.JsonGenerator.currentValue.

Helper method, usually equivalent to: getOutputContext().currentValue();

Note that "current value" is NOT populated (or used) by Streaming generator; it is only used by higher-level data-binding functionality.

public SmileGenerator
public SmileGenerator
public final void
flush()

Implements abstract tools.jackson.core.JsonGenerator.flush.

Implements java.io.Flushable.flush.

Method called to flush any buffered content to the underlying target (output stream, writer), and to flush the target itself as well.

public PrettyPrinter
getPrettyPrinter()

Overrides tools.jackson.core.JsonGenerator.getPrettyPrinter.

Accessor for object that handles pretty-printing (usually additional white space to make results more human-readable) during output.

public final boolean
protected long
outputOffset()

Method for accessing offset of the next byte within the whole output stream that this generator has produced.

public JacksonFeatureSet<StreamWriteCapability>
streamWriteCapabilities()

Implements abstract tools.jackson.core.JsonGenerator.streamWriteCapabilities.

Accessor for getting metadata on capabilities of this generator, based on underlying data format being read (directly or indirectly).

public TokenStreamContext
streamWriteContext()

Implements abstract tools.jackson.core.JsonGenerator.streamWriteContext.

Accessor for context object that provides information about low-level logical position withing output token stream.

public int
streamWriteOutputBuffered()

Implements abstract tools.jackson.core.JsonGenerator.streamWriteOutputBuffered.

Method for verifying amount of content that is buffered by generator but not yet flushed to the underlying target (stream, writer), in units (byte, char) that the generator implementation uses for buffering; or -1 if this information is not available.

public Object
streamWriteOutputTarget()

Implements abstract tools.jackson.core.JsonGenerator.streamWriteOutputTarget.

Method that can be used to get access to object that is used as target for generated output; this is usually either java.io.OutputStream or java.io.Writer, depending on what generator was constructed with.

public Version
version()

Implements abstract tools.jackson.core.JsonGenerator.version.

Implements tools.jackson.core.Versioned.version.

Accessor for finding out version of the bundle that provided this generator instance.

public JsonGenerator
writeArray(int[] array, int offset, int length)

Overrides tools.jackson.core.JsonGenerator.writeArray.

Value write method that can be called to write a single array (sequence of JsonToken#START_ARRAY, zero or more JsonToken#VALUE_NUMBER_INT, JsonToken#END_ARRAY)

public JsonGenerator
writeArray(long[] array, int offset, int length)

Overrides tools.jackson.core.JsonGenerator.writeArray.

Value write method that can be called to write a single array (sequence of JsonToken#START_ARRAY, zero or more JsonToken#VALUE_NUMBER_INT, JsonToken#END_ARRAY)

public JsonGenerator
writeArray(double[] array, int offset, int length)

Overrides tools.jackson.core.JsonGenerator.writeArray.

Value write method that can be called to write a single array (sequence of JsonToken#START_ARRAY, zero or more JsonToken#VALUE_NUMBER_FLOAT, JsonToken#END_ARRAY)

public JsonGenerator
writeBinary(Base64Variant b64variant, byte[] data, int offset, int len)

Implements abstract tools.jackson.core.JsonGenerator.writeBinary.

Method that will output given chunk of binary data as base64 encoded, as a complete String value (surrounded by double quotes).

public int
writeBinary(InputStream data, int dataLength)

Overrides tools.jackson.core.JsonGenerator.writeBinary.

Similar to writeBinary(Base64Variant, InputStream, int), but assumes default to using the Jackson default Base64 variant (which is Base64Variants#MIME_NO_LINEFEEDS).

public int
writeBinary(Base64Variant b64variant, InputStream data, int dataLength)

Overrides tools.jackson.core.base.GeneratorBase.writeBinary.

Method similar to writeBinary(Base64Variant, byte[], int, int), but where input is provided through a stream, allowing for incremental writes without holding the whole input in memory.

public JsonGenerator
writeBoolean(boolean state)

Implements abstract tools.jackson.core.JsonGenerator.writeBoolean.

Method for outputting literal JSON boolean value (one of Strings 'true' and 'false').

public JsonGenerator
writeBytes(byte[] data, int offset, int len)

Method for directly inserting specified bytes in output at current position.

public JsonGenerator
writeEndArray()

Implements abstract tools.jackson.core.JsonGenerator.writeEndArray.

Method for writing closing marker of a JSON Array value (character ']'; plus possible white space decoration if pretty-printing is enabled).

public JsonGenerator
writeEndObject()

Implements abstract tools.jackson.core.JsonGenerator.writeEndObject.

Method for writing closing marker of an Object value (character '}'; plus possible white space decoration if pretty-printing is enabled).

public JsonGenerator
writeHeader()

Method that can be called to explicitly write Smile document header.

public JsonGenerator
writeName(String name)

Implements abstract tools.jackson.core.JsonGenerator.writeName.

Method for writing an Object Property name (JSON String surrounded by double quotes: syntactically identical to a JSON String value), possibly decorated by white space if pretty-printing is enabled.

public JsonGenerator
writeName(SerializableString name)

Overrides tools.jackson.core.base.GeneratorBase.writeName.

Method similar to writeName(String), main difference being that it may perform better as some of processing (such as quoting of certain characters, or encoding into external encoding if supported by generator) can be done just once and reused for later calls.

public JsonGenerator
writeNull()

Implements abstract tools.jackson.core.JsonGenerator.writeNull.

Method for outputting literal JSON null value.

public JsonGenerator
writeNumber(short v)

Implements abstract tools.jackson.core.JsonGenerator.writeNumber.

Method for outputting given value as JSON number.

public JsonGenerator
writeNumber(int i)

Implements abstract tools.jackson.core.JsonGenerator.writeNumber.

Method for outputting given value as JSON number.

public JsonGenerator
writeNumber(long l)

Implements abstract tools.jackson.core.JsonGenerator.writeNumber.

Method for outputting given value as JSON number.

public JsonGenerator
writeNumber(BigInteger v)

Implements abstract tools.jackson.core.JsonGenerator.writeNumber.

Method for outputting given value as JSON number.

public JsonGenerator
writeNumber(double d)

Implements abstract tools.jackson.core.JsonGenerator.writeNumber.

Method for outputting indicate JSON numeric value.

public JsonGenerator
writeNumber(float f)

Implements abstract tools.jackson.core.JsonGenerator.writeNumber.

Method for outputting indicate JSON numeric value.

public JsonGenerator
writeNumber(BigDecimal dec)

Implements abstract tools.jackson.core.JsonGenerator.writeNumber.

Method for outputting indicate JSON numeric value.

public JsonGenerator
writeNumber(String encodedValue)

Implements abstract tools.jackson.core.JsonGenerator.writeNumber.

Write method that can be used for custom numeric types that can not be (easily?) converted to "standard" Java number types.

public JsonGenerator
writePropertyId(long id)

Implements abstract tools.jackson.core.JsonGenerator.writePropertyId.

Alternative to writeName(String) that may be used in cases where Object Property key is of numeric type; usually where underlying format supports such notion (some binary formats do, unlike JSON).

public JsonGenerator
writeRaw(byte b)

Method for directly inserting specified byte in output at current position.

public JsonGenerator
writeRaw(String text)

Implements abstract tools.jackson.core.JsonGenerator.writeRaw.

Method that will force generator to copy input text verbatim with no modifications (including that no escaping is done and no separators are added even if context [array, object] would otherwise require such).

public JsonGenerator
writeRaw(String text, int offset, int len)

Implements abstract tools.jackson.core.JsonGenerator.writeRaw.

Method that will force generator to copy input text verbatim with no modifications (including that no escaping is done and no separators are added even if context [array, object] would otherwise require such).

public JsonGenerator
writeRaw(char[] text, int offset, int len)

Implements abstract tools.jackson.core.JsonGenerator.writeRaw.

Method that will force generator to copy input text verbatim with no modifications (including that no escaping is done and no separators are added even if context [array, object] would otherwise require such).

public JsonGenerator
writeRaw(char c)

Implements abstract tools.jackson.core.JsonGenerator.writeRaw.

Method that will force generator to copy input text verbatim with no modifications (including that no escaping is done and no separators are added even if context [array, object] would otherwise require such).

public JsonGenerator
writeRawUTF8String(byte[] text, int offset, int len)

Implements abstract tools.jackson.core.JsonGenerator.writeRawUTF8String.

Method similar to writeString(String) but that takes as its input a UTF-8 encoded String that is to be output as-is, without additional escaping (type of which depends on data format; backslashes for JSON).

public JsonGenerator
writeRawValue(String text)

Overrides tools.jackson.core.base.GeneratorBase.writeRawValue.

Method that will force generator to copy input text verbatim without any modifications, but assuming it must constitute a single legal JSON value (number, string, boolean, null, Array or List).

public JsonGenerator
public JsonGenerator
writeRawValue(char[] text, int offset, int len)

Overrides tools.jackson.core.base.GeneratorBase.writeRawValue.

public JsonGenerator
writeStartArray()

Implements abstract tools.jackson.core.JsonGenerator.writeStartArray.

Method for writing starting marker of a Array value (for JSON this is character '['; plus possible white space decoration if pretty-printing is enabled).

public JsonGenerator
writeStartArray(Object forValue)

Implements abstract tools.jackson.core.JsonGenerator.writeStartArray.

Method for writing start marker of an Array value, similar to writeStartArray(), but also specifying what is the Java object that the Array Object being written represents (if any); null may be passed if not known or not applicable.

public JsonGenerator
writeStartArray(Object forValue, int size)

Overrides tools.jackson.core.base.GeneratorBase.writeStartArray.

Method for writing start marker of an Array value, similar to writeStartArray(), but also specifying what is the Java object that the Array Object being written represents (if any) and how many elements will be written for the array before calling writeEndArray().

public JsonGenerator
writeStartObject()

Implements abstract tools.jackson.core.JsonGenerator.writeStartObject.

Method for writing starting marker of an Object value (character '{'; plus possible white space decoration if pretty-printing is enabled).

public JsonGenerator
writeStartObject(Object forValue)

Implements abstract tools.jackson.core.JsonGenerator.writeStartObject.

Method for writing starting marker of an Object value to represent the given Java Object value.

public JsonGenerator
writeStartObject(Object forValue, int size)

Overrides tools.jackson.core.base.GeneratorBase.writeStartObject.

Method for writing starting marker of an Object value to represent the given Java Object value.

public JsonGenerator
writeString(String text)

Implements abstract tools.jackson.core.JsonGenerator.writeString.

Method for outputting a String value.

public JsonGenerator
writeString(char[] text, int offset, int len)

Implements abstract tools.jackson.core.JsonGenerator.writeString.

Method for outputting a String value.

public JsonGenerator
writeString(SerializableString sstr)

Overrides tools.jackson.core.base.GeneratorBase.writeString.

Method similar to writeString(String), but that takes SerializableString which can make this potentially more efficient to call as generator may be able to reuse quoted and/or encoded representation.

public JsonGenerator
writeUTF8String(byte[] text, int offset, int len)

Implements abstract tools.jackson.core.JsonGenerator.writeUTF8String.

Method similar to writeString(String) but that takes as its input a UTF-8 encoded String which has not been escaped using whatever escaping scheme data format requires (for JSON that is backslash-escaping for control characters and double-quotes; for other formats something else).

Inherited from tools.jackson.core.base.GeneratorBase:
_asString_checkRangeBoundsForByteArray_checkRangeBoundsForCharArray_checkRangeBoundsForString_constructDefaultPrettyPrinter_decodeSurrogate_throwInternalcloseconfigurehasioContextisClosedisEnabledobjectWriteContextstreamWriteConstraintsstreamWriteFeatureswritePOJOwriteRawValuewriteStringwriteTree