Search in sources :

Example 26 with IOContext

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

the class UTF8DataInputJsonParserTest method testGetTextOffsetAndNextFieldName.

@Test
public void testGetTextOffsetAndNextFieldName() throws IOException {
    byte[] byteArray = new byte[2];
    byteArray[1] = (byte) 91;
    IOContext ioContext = new IOContext(new BufferRecycler(), byteArray, false);
    InputStream byteArrayInputStream = new ByteArrayInputStream(byteArray);
    DataInputStream dataInputStream = new DataInputStream(byteArrayInputStream);
    ByteQuadsCanonicalizer byteQuadsCanonicalizer = ByteQuadsCanonicalizer.createRoot();
    UTF8DataInputJsonParser uTF8DataInputJsonParser = new UTF8DataInputJsonParser(ObjectReadContext.empty(), ioContext, 42, dataInputStream, byteQuadsCanonicalizer, 0);
    assertEquals(0, uTF8DataInputJsonParser.getTextOffset());
    assertNull(uTF8DataInputJsonParser.nextFieldName());
}
Also used : BufferRecycler(com.fasterxml.jackson.core.util.BufferRecycler) IOContext(com.fasterxml.jackson.core.io.IOContext) ByteQuadsCanonicalizer(com.fasterxml.jackson.core.sym.ByteQuadsCanonicalizer) BaseTest(com.fasterxml.jackson.core.BaseTest) Test(org.junit.Test)

Example 27 with IOContext

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

the class UTF8DataInputJsonParserTest method test_skipStringThrowsIOException.

@Test
public void test_skipStringThrowsIOException() {
    IOContext ioContext = new IOContext(new BufferRecycler(), this, false);
    byte[] byteArray = new byte[12];
    byteArray[4] = (byte) (-10);
    InputStream byteArrayInputStream = new ByteArrayInputStream(byteArray);
    DataInputStream dataInputStream = new DataInputStream(byteArrayInputStream);
    UTF8DataInputJsonParser uTF8DataInputJsonParser = new UTF8DataInputJsonParser(ObjectReadContext.empty(), ioContext, 100, dataInputStream, null, 11);
    try {
        uTF8DataInputJsonParser._skipString();
        fail("Expecting exception: IOException");
    } catch (IOException e) {
        assertEquals(JsonParser.class.getName(), e.getStackTrace()[0].getClassName());
    }
}
Also used : BufferRecycler(com.fasterxml.jackson.core.util.BufferRecycler) IOContext(com.fasterxml.jackson.core.io.IOContext) BaseTest(com.fasterxml.jackson.core.BaseTest) Test(org.junit.Test)

Example 28 with IOContext

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

the class UTF8DataInputJsonParserTest method testNextTextValueThrowsIOException.

@Test
public void testNextTextValueThrowsIOException() {
    IOContext ioContext = new IOContext(new BufferRecycler(), this, false);
    byte[] byteArray = new byte[20];
    byteArray[0] = (byte) 47;
    InputStream byteArrayInputStream = new ByteArrayInputStream(byteArray);
    DataInputStream dataInputStream = new DataInputStream(byteArrayInputStream);
    UTF8DataInputJsonParser uTF8DataInputJsonParser = new UTF8DataInputJsonParser(ObjectReadContext.empty(), ioContext, 915, dataInputStream, null, (byte) 47);
    try {
        uTF8DataInputJsonParser.nextTextValue();
        fail("Expecting exception: IOException");
    } catch (IOException e) {
        assertEquals(JsonParser.class.getName(), e.getStackTrace()[0].getClassName());
    }
}
Also used : BufferRecycler(com.fasterxml.jackson.core.util.BufferRecycler) IOContext(com.fasterxml.jackson.core.io.IOContext) BaseTest(com.fasterxml.jackson.core.BaseTest) Test(org.junit.Test)

Example 29 with IOContext

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

the class BinaryTSFactory method createParser.

@Override
public JsonParser createParser(ObjectReadContext readCtxt, URL url) throws IOException {
    // true, since we create InputStream from URL
    IOContext ioCtxt = _createContext(url, true);
    InputStream in = _optimizedStreamFromURL(url);
    return _createParser(readCtxt, ioCtxt, _decorate(ioCtxt, in));
}
Also used : IOContext(com.fasterxml.jackson.core.io.IOContext)

Example 30 with IOContext

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

the class BinaryTSFactory method createGenerator.

@Override
public JsonGenerator createGenerator(ObjectWriteContext writeCtxt, File f, JsonEncoding enc) throws IOException {
    OutputStream out = new FileOutputStream(f);
    // true -> yes, we have to manage the stream since we created it
    IOContext ioCtxt = _createContext(out, true, enc);
    return _createGenerator(writeCtxt, ioCtxt, _decorate(ioCtxt, out));
}
Also used : 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