Search in sources :

Example 1 with BufferRecycler

use of org.codehaus.jackson.util.BufferRecycler in project databus by linkedin.

the class AbstractRequestProcesser method createJsonGenerator.

protected JsonGenerator createJsonGenerator(ObjectCodec codec, Writer writer, boolean prettyPrint) {
    IOContext ioCtx = new IOContext(new BufferRecycler(), null, true);
    WriterBasedGenerator result = new WriterBasedGenerator(ioCtx, 0, codec, writer);
    result.configure(Feature.QUOTE_FIELD_NAMES, true);
    if (prettyPrint)
        result.useDefaultPrettyPrinter();
    return result;
}
Also used : WriterBasedGenerator(org.codehaus.jackson.impl.WriterBasedGenerator) BufferRecycler(org.codehaus.jackson.util.BufferRecycler) IOContext(org.codehaus.jackson.io.IOContext)

Example 2 with BufferRecycler

use of org.codehaus.jackson.util.BufferRecycler in project stargate-core by tuplejump.

the class Group method toByteBuffer.

public ByteBuffer toByteBuffer() throws IOException {
    BufferRecycler bufferRecycler = bufferThreadLocal.get();
    ByteArrayBuilder bytes = new ByteArrayBuilder(bufferRecycler);
    IOContext ioContext = new IOContext(bufferRecycler, bytes, false);
    JsonGenerator gen = new Utf8Generator(ioContext, 0, null, bytes);
    gen.enable(JsonGenerator.Feature.QUOTE_FIELD_NAMES);
    gen.enable(JsonGenerator.Feature.QUOTE_NON_NUMERIC_NUMBERS);
    gen.enable(JsonGenerator.Feature.ESCAPE_NON_ASCII);
    writeJson(gen);
    gen.flush();
    bytes.flush();
    bytes.close();
    return ByteBuffer.wrap(bytes.toByteArray());
}
Also used : BufferRecycler(org.codehaus.jackson.util.BufferRecycler) IOContext(org.codehaus.jackson.io.IOContext) JsonGenerator(org.codehaus.jackson.JsonGenerator) ByteArrayBuilder(org.codehaus.jackson.util.ByteArrayBuilder) Utf8Generator(org.codehaus.jackson.impl.Utf8Generator)

Aggregations

IOContext (org.codehaus.jackson.io.IOContext)2 BufferRecycler (org.codehaus.jackson.util.BufferRecycler)2 JsonGenerator (org.codehaus.jackson.JsonGenerator)1 Utf8Generator (org.codehaus.jackson.impl.Utf8Generator)1 WriterBasedGenerator (org.codehaus.jackson.impl.WriterBasedGenerator)1 ByteArrayBuilder (org.codehaus.jackson.util.ByteArrayBuilder)1