Java源码示例:com.fasterxml.jackson.dataformat.smile.SmileGenerator

示例1
/**
 * Serializes the {@code message} into an {@link OutputStream} using the given {@code schema}.
 */
public static <T> void writeTo(OutputStream out, T message, Schema<T> schema,
        boolean numeric) throws IOException
{
    final IOContext context = new IOContext(DEFAULT_SMILE_FACTORY._getBufferRecycler(),
            out, false);

    final SmileGenerator generator = newSmileGenerator(out,
            context.allocWriteEncodingBuffer(), 0, true, context);

    // final SmileGenerator generator = DEFAULT_SMILE_FACTORY.createJsonGenerator(out);

    try
    {
        JsonIOUtil.writeTo(generator, message, schema, numeric);
    }
    finally
    {
        generator.close();
    }
}
 
示例2
/**
 * Serializes the {@code message} into an {@link OutputStream} using the given {@code schema}.
 * <p>
 * The {@link LinkedBuffer}'s internal byte array will be used as the primary buffer when writing the message.
 */
public static <T> void writeTo(OutputStream out, T message, Schema<T> schema,
        boolean numeric, LinkedBuffer buffer) throws IOException
{
    final IOContext context = new IOContext(DEFAULT_SMILE_FACTORY._getBufferRecycler(),
            out, false);

    final SmileGenerator generator = newSmileGenerator(out, buffer.buffer, 0, false,
            context);

    // final SmileGenerator generator = DEFAULT_SMILE_FACTORY.createJsonGenerator(out);
    try
    {
        JsonIOUtil.writeTo(generator, message, schema, numeric);
    }
    finally
    {
        generator.close();
    }
}
 
示例3
/**
 * Serializes the {@code messages} into the stream using the given schema.
 */
public static <T> void writeListTo(OutputStream out, List<T> messages,
        Schema<T> schema, boolean numeric) throws IOException
{
    final IOContext context = new IOContext(DEFAULT_SMILE_FACTORY._getBufferRecycler(),
            out, false);

    final SmileGenerator generator = newSmileGenerator(out,
            context.allocWriteEncodingBuffer(), 0, true, context);

    // final SmileGenerator generator = DEFAULT_SMILE_FACTORY.createJsonGenerator(out);
    try
    {
        JsonIOUtil.writeListTo(generator, messages, schema, numeric);
    }
    finally
    {
        generator.close();
    }
}
 
示例4
/**
 * Serializes the {@code messages} into the stream using the given schema.
 * <p>
 * The {@link LinkedBuffer}'s internal byte array will be used as the primary buffer when writing the message.
 */
public static <T> void writeListTo(OutputStream out, List<T> messages,
        Schema<T> schema, boolean numeric, LinkedBuffer buffer) throws IOException
{
    final IOContext context = new IOContext(DEFAULT_SMILE_FACTORY._getBufferRecycler(),
            out, false);

    final SmileGenerator generator = newSmileGenerator(out, buffer.buffer, 0, false,
            context);

    // final SmileGenerator generator = DEFAULT_SMILE_FACTORY.createJsonGenerator(out);
    try
    {
        JsonIOUtil.writeListTo(generator, messages, schema, numeric);
    }
    finally
    {
        generator.close();
    }
}
 
示例5
public SmileWriter(OutputStream out, SolrQueryRequest req, SolrQueryResponse rsp) {
  super(null, req, rsp);
  this.out = out;
  SmileFactory smileFactory = new SmileFactory();
  smileFactory.enable(SmileGenerator.Feature.CHECK_SHARED_NAMES);
  try {
    gen = smileFactory.createGenerator(this.out, null);
  } catch (IOException e) {
    throw new RuntimeException(e);
  }
}
 
示例6
/**
 * Creates a {@link SmileGenerator} for the outputstream with the supplied buf {@code outBuffer} to use.
 */
static SmileGenerator newSmileGenerator(OutputStream out, byte[] buf, int offset,
        boolean bufferRecyclable, IOContext context)
{
    return new SmileGenerator(context,
            DEFAULT_SMILE_FACTORY.getGeneratorFeaturesImpl(),
            DEFAULT_SMILE_FACTORY.getSmileGeneratorFeatures(),
            DEFAULT_SMILE_FACTORY.getCodec(),
            out,
            buf,
            offset,
            bufferRecyclable);
}
 
示例7
public TreeSerializer() {
    var f = new SmileFactory();
    f.configure(SmileGenerator.Feature.CHECK_SHARED_STRING_VALUES, true);
    this.mapper = new ObjectMapper(f).setSerializationInclusion(JsonInclude.Include.NON_NULL);
}
 
示例8
/**
 * Creates a {@link SmileGenerator} for the outputstream with the supplied buf {@code outBuffer} to use.
 */
public static SmileGenerator newSmileGenerator(OutputStream out, byte[] buf)
{
    return newSmileGenerator(out, buf, 0, false, new IOContext(
            DEFAULT_SMILE_FACTORY._getBufferRecycler(), out, false));
}