Search in sources :

Example 36 with IOContext

use of com.fasterxml.jackson.core.io.IOContext in project jackson-core by FasterXML.

the class TextualTSFactory method createGenerator.

@Override
public JsonGenerator createGenerator(ObjectWriteContext writeCtxt, File f, JsonEncoding enc) throws IOException {
    OutputStream out = new FileOutputStream(f);
    IOContext ioCtxt = _createContext(f, true, enc);
    if (enc == JsonEncoding.UTF8) {
        return _createUTF8Generator(writeCtxt, ioCtxt, _decorate(ioCtxt, out));
    }
    return _createGenerator(writeCtxt, ioCtxt, _decorate(ioCtxt, _createWriter(ioCtxt, out, enc)));
}
Also used : IOContext(com.fasterxml.jackson.core.io.IOContext)

Example 37 with IOContext

use of com.fasterxml.jackson.core.io.IOContext in project jackson-core by FasterXML.

the class JsonParserSequenceTest method testClose.

@Test
public void testClose() throws IOException {
    IOContext ioContext = new IOContext(new BufferRecycler(), this, true);
    ReaderBasedJsonParser readerBasedJsonParser = new ReaderBasedJsonParser(ObjectReadContext.empty(), ioContext, 2, null, CharsToNameCanonicalizer.createRoot());
    JsonParserSequence jsonParserSequence = JsonParserSequence.createFlattened(true, readerBasedJsonParser, readerBasedJsonParser);
    assertFalse(jsonParserSequence.isClosed());
    jsonParserSequence.close();
    assertTrue(jsonParserSequence.isClosed());
    assertNull(jsonParserSequence.nextToken());
}
Also used : IOContext(com.fasterxml.jackson.core.io.IOContext) ReaderBasedJsonParser(com.fasterxml.jackson.core.json.ReaderBasedJsonParser) BaseTest(com.fasterxml.jackson.core.BaseTest) Test(org.junit.Test)

Example 38 with IOContext

use of com.fasterxml.jackson.core.io.IOContext in project jackson-core by FasterXML.

the class JsonParserSequenceTest method testSkipChildren.

@Test
public void testSkipChildren() throws IOException {
    JsonParser[] jsonParserArray = new JsonParser[3];
    IOContext ioContext = new IOContext(new BufferRecycler(), jsonParserArray, true);
    byte[] byteArray = new byte[8];
    InputStream byteArrayInputStream = new ByteArrayInputStream(byteArray, 0, (byte) 58);
    UTF8StreamJsonParser uTF8StreamJsonParser = new UTF8StreamJsonParser(ObjectReadContext.empty(), ioContext, 0, byteArrayInputStream, ByteQuadsCanonicalizer.createRoot(), byteArray, -1, (byte) 9, true);
    JsonParserDelegate jsonParserDelegate = new JsonParserDelegate(jsonParserArray[0]);
    JsonParserSequence jsonParserSequence = JsonParserSequence.createFlattened(true, uTF8StreamJsonParser, jsonParserDelegate);
    JsonParserSequence jsonParserSequenceTwo = (JsonParserSequence) jsonParserSequence.skipChildren();
    assertEquals(2, jsonParserSequenceTwo.containedParsersCount());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) IOContext(com.fasterxml.jackson.core.io.IOContext) UTF8StreamJsonParser(com.fasterxml.jackson.core.json.UTF8StreamJsonParser) ReaderBasedJsonParser(com.fasterxml.jackson.core.json.ReaderBasedJsonParser) JsonParser(com.fasterxml.jackson.core.JsonParser) UTF8StreamJsonParser(com.fasterxml.jackson.core.json.UTF8StreamJsonParser) BaseTest(com.fasterxml.jackson.core.BaseTest) Test(org.junit.Test)

Example 39 with IOContext

use of com.fasterxml.jackson.core.io.IOContext in project neo4j by neo4j.

the class StreamingJsonFormat method createJsonFactory.

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

        @Override
        protected JsonGenerator _createUTF8Generator(OutputStream out, IOContext ctxt) {
            final int bufferSize = 1024 * 8;
            UTF8JsonGenerator gen = new UTF8JsonGenerator(ctxt, _generatorFeatures, _objectCodec, out, DEFAULT_QUOTE_CHAR, 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 : UTF8JsonGenerator(com.fasterxml.jackson.core.json.UTF8JsonGenerator) OutputStream(java.io.OutputStream) JsonFactory(com.fasterxml.jackson.core.JsonFactory) IOContext(com.fasterxml.jackson.core.io.IOContext) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 40 with IOContext

use of com.fasterxml.jackson.core.io.IOContext in project bson4jackson by michel-kraemer.

the class BsonFactory method createParser.

@Override
public BsonParser createParser(URL url) throws IOException {
    IOContext ctxt = _createContext(url, true);
    InputStream in = _optimizedStreamFromURL(url);
    if (_inputDecorator != null) {
        in = _inputDecorator.decorate(ctxt, in);
    }
    return _createParser(in, ctxt);
}
Also used : FileInputStream(java.io.FileInputStream) UnsafeByteArrayInputStream(de.undercouch.bson4jackson.io.UnsafeByteArrayInputStream) InputStream(java.io.InputStream) IOContext(com.fasterxml.jackson.core.io.IOContext)

Aggregations

IOContext (com.fasterxml.jackson.core.io.IOContext)41 BufferRecycler (com.fasterxml.jackson.core.util.BufferRecycler)28 BaseTest (com.fasterxml.jackson.core.BaseTest)18 Test (org.junit.Test)18 ByteQuadsCanonicalizer (com.fasterxml.jackson.core.sym.ByteQuadsCanonicalizer)8 UTF8Writer (com.fasterxml.jackson.core.io.UTF8Writer)5 BsonBinaryReader (org.bson.BsonBinaryReader)5 BsonBinaryWriter (org.bson.BsonBinaryWriter)5 BasicOutputBuffer (org.bson.io.BasicOutputBuffer)5 BsonWriter (org.bson.BsonWriter)4 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)3 InputStream (java.io.InputStream)3 JsonParser (com.fasterxml.jackson.core.JsonParser)2 ReaderBasedJsonParser (com.fasterxml.jackson.core.json.ReaderBasedJsonParser)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 UnsafeByteArrayInputStream (de.undercouch.bson4jackson.io.UnsafeByteArrayInputStream)2 FileInputStream (java.io.FileInputStream)2 OutputStream (java.io.OutputStream)2 BsonDocument (org.bson.BsonDocument)2 JsonFactory (com.fasterxml.jackson.core.JsonFactory)1