Search in sources :

Example 31 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 32 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 33 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 34 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)

Example 35 with IOContext

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

the class BsonFactory method createGenerator.

@Override
public BsonGenerator createGenerator(File f, JsonEncoding enc) throws IOException {
    OutputStream out = new FileOutputStream(f);
    IOContext ctxt = _createContext(out, true);
    ctxt.setEncoding(enc);
    if (enc == JsonEncoding.UTF8 && _outputDecorator != null) {
        out = _outputDecorator.decorate(ctxt, out);
    }
    return createGenerator(out, enc);
}
Also used : OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) IOContext(com.fasterxml.jackson.core.io.IOContext)

Aggregations

IOContext (com.fasterxml.jackson.core.io.IOContext)35 BufferRecycler (com.fasterxml.jackson.core.util.BufferRecycler)23 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 InputStream (java.io.InputStream)3 JsonParser (com.fasterxml.jackson.core.JsonParser)2 ReaderBasedJsonParser (com.fasterxml.jackson.core.json.ReaderBasedJsonParser)2 UnsafeByteArrayInputStream (de.undercouch.bson4jackson.io.UnsafeByteArrayInputStream)2 FileInputStream (java.io.FileInputStream)2 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)1 JsonToken (com.fasterxml.jackson.core.JsonToken)1 ObjectCodec (com.fasterxml.jackson.core.ObjectCodec)1 MergedStream (com.fasterxml.jackson.core.io.MergedStream)1 UTF8StreamJsonParser (com.fasterxml.jackson.core.json.UTF8StreamJsonParser)1 ByteArrayBuilder (com.fasterxml.jackson.core.util.ByteArrayBuilder)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 FileOutputStream (java.io.FileOutputStream)1