Search in sources :

Example 6 with IOContext

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

the class UTF8DataInputJsonParserTest method test_parseAposNameThrowsEOFException.

@Test
public void test_parseAposNameThrowsEOFException() throws IOException {
    IOContext ioContext = new IOContext(new BufferRecycler(), this, false);
    byte[] byteArray = new byte[17];
    byteArray[4] = (byte) 43;
    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);
    try {
        uTF8DataInputJsonParser._parseAposName();
        fail("Expecting exception: EOFException");
    } catch (EOFException e) {
        assertEquals(DataInputStream.class.getName(), e.getStackTrace()[0].getClassName());
    }
}
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 7 with IOContext

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

the class UTF8DataInputJsonParserTest method testGetNextFieldNameAndGetTextLength.

@Test
public void testGetNextFieldNameAndGetTextLength() 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);
    UTF8DataInputJsonParser uTF8DataInputJsonParser = new UTF8DataInputJsonParser(ObjectReadContext.empty(), ioContext, 42, dataInputStream, ByteQuadsCanonicalizer.createRoot(), 0);
    uTF8DataInputJsonParser.nextFieldName();
    assertNull(uTF8DataInputJsonParser.getObjectId());
    assertEquals(1, uTF8DataInputJsonParser.getTextLength());
}
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 8 with IOContext

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

the class UTF8DataInputJsonParserTest method test_parsePosNumber.

@Test
public void test_parsePosNumber() throws IOException {
    byte[] byteArray = new byte[2];
    byteArray[0] = (byte) 51;
    byteArray[1] = (byte) 22;
    IOContext ioContext = new IOContext(new BufferRecycler(), byteArray, false);
    InputStream byteArrayInputStream = new ByteArrayInputStream(byteArray);
    ByteQuadsCanonicalizer byteQuadsCanonicalizer = ByteQuadsCanonicalizer.createRoot();
    DataInputStream dataInputStream = new DataInputStream(byteArrayInputStream);
    UTF8DataInputJsonParser uTF8DataInputJsonParser = new UTF8DataInputJsonParser(ObjectReadContext.empty(), ioContext, 1568, dataInputStream, byteQuadsCanonicalizer, 13);
    JsonToken jsonToken = uTF8DataInputJsonParser._parsePosNumber(7);
    assertEquals(7, jsonToken.id());
    assertNull(jsonToken.asString());
}
Also used : BufferRecycler(com.fasterxml.jackson.core.util.BufferRecycler) IOContext(com.fasterxml.jackson.core.io.IOContext) ByteQuadsCanonicalizer(com.fasterxml.jackson.core.sym.ByteQuadsCanonicalizer) JsonToken(com.fasterxml.jackson.core.JsonToken) BaseTest(com.fasterxml.jackson.core.BaseTest) Test(org.junit.Test)

Example 9 with IOContext

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

the class UTF8DataInputJsonParserTest method test_parseNegNumberThrowsIOException.

@Test
public void test_parseNegNumberThrowsIOException() throws IOException {
    IOContext ioContext = new IOContext(new BufferRecycler(), this, false);
    byte[] byteArray = new byte[20];
    byteArray[2] = (byte) 73;
    InputStream byteArrayInputStream = new ByteArrayInputStream(byteArray);
    DataInputStream dataInputStream = new DataInputStream(byteArrayInputStream);
    UTF8DataInputJsonParser uTF8DataInputJsonParser = new UTF8DataInputJsonParser(ObjectReadContext.empty(), ioContext, 100, dataInputStream, null, 3);
    dataInputStream.readUnsignedShort();
    try {
        uTF8DataInputJsonParser._parseNegNumber();
        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 10 with IOContext

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

the class UTF8DataInputJsonParserTest method testNextFieldNameThrowsIOException.

@Test
public void testNextFieldNameThrowsIOException() {
    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, 100, dataInputStream, null, -2624);
    try {
        uTF8DataInputJsonParser.nextFieldName();
        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)

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