Search in sources :

Example 1 with Utf8Generator

use of org.codehaus.jackson.impl.Utf8Generator 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)

Example 2 with Utf8Generator

use of org.codehaus.jackson.impl.Utf8Generator in project neo4j by neo4j.

the class StreamingJsonFormat method createJsonFactory.

private JsonFactory createJsonFactory() {
    final ObjectMapper objectMapper = new ObjectMapper();
    objectMapper.getSerializationConfig().disable(SerializationConfig.Feature.FLUSH_AFTER_WRITE_VALUE);
    JsonFactory factory = new JsonFactory(objectMapper) {

        @Override
        protected JsonGenerator _createUTF8JsonGenerator(OutputStream out, IOContext ctxt) throws IOException {
            final int bufferSize = 1024 * 8;
            Utf8Generator gen = new Utf8Generator(ctxt, _generatorFeatures, _objectCodec, out, new byte[bufferSize], 0, true);
            if (_characterEscapes != null) {
                gen.setCharacterEscapes(_characterEscapes);
            }
            return gen;
        }
    };
    factory.disable(JsonGenerator.Feature.FLUSH_PASSED_TO_STREAM);
    return factory;
}
Also used : OutputStream(java.io.OutputStream) JsonFactory(org.codehaus.jackson.JsonFactory) IOContext(org.codehaus.jackson.io.IOContext) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) Utf8Generator(org.codehaus.jackson.impl.Utf8Generator)

Aggregations

Utf8Generator (org.codehaus.jackson.impl.Utf8Generator)2 IOContext (org.codehaus.jackson.io.IOContext)2 OutputStream (java.io.OutputStream)1 JsonFactory (org.codehaus.jackson.JsonFactory)1 JsonGenerator (org.codehaus.jackson.JsonGenerator)1 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)1 BufferRecycler (org.codehaus.jackson.util.BufferRecycler)1 ByteArrayBuilder (org.codehaus.jackson.util.ByteArrayBuilder)1