Search in sources :

Example 11 with ByteQuadsCanonicalizer

use of com.fasterxml.jackson.core.sym.ByteQuadsCanonicalizer in project jackson-core by FasterXML.

the class UTF8DataInputJsonParserTest method testReadBinaryValueThrowsIOException.

@Test
public void testReadBinaryValueThrowsIOException() {
    BufferRecycler bufferRecycler = new BufferRecycler();
    IOContext ioContext = new IOContext(bufferRecycler, this, false);
    ByteQuadsCanonicalizer byteQuadsCanonicalizer = ByteQuadsCanonicalizer.createRoot();
    UTF8DataInputJsonParser uTF8DataInputJsonParser = new UTF8DataInputJsonParser(ObjectReadContext.empty(), ioContext, (-53), null, byteQuadsCanonicalizer, 48);
    ByteArrayBuilder byteArrayBuilder = new ByteArrayBuilder(bufferRecycler, 1);
    try {
        uTF8DataInputJsonParser.readBinaryValue(null, byteArrayBuilder);
        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) ByteQuadsCanonicalizer(com.fasterxml.jackson.core.sym.ByteQuadsCanonicalizer) ByteArrayBuilder(com.fasterxml.jackson.core.util.ByteArrayBuilder) BaseTest(com.fasterxml.jackson.core.BaseTest) Test(org.junit.Test)

Example 12 with ByteQuadsCanonicalizer

use of com.fasterxml.jackson.core.sym.ByteQuadsCanonicalizer 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 13 with ByteQuadsCanonicalizer

use of com.fasterxml.jackson.core.sym.ByteQuadsCanonicalizer in project jackson-core by FasterXML.

the class AsyncParserNamesTest method testSymbolTable.

public void testSymbolTable() throws IOException {
    final String STR1 = "a";
    byte[] doc = _jsonDoc("{ " + quote(STR1) + ":1, \"foobar\":2, \"longername\":3 }");
    JsonFactory f = JSON_F;
    AsyncReaderWrapper p = asyncForBytes(f, 5, doc, 0);
    final ByteQuadsCanonicalizer symbols1 = ((NonBlockingJsonParserBase) p.parser()).symbolTableForTests();
    assertEquals(0, symbols1.size());
    assertEquals(JsonToken.START_OBJECT, p.nextToken());
    assertEquals(JsonToken.FIELD_NAME, p.nextToken());
    // field names not intern()ed by default any more in 3.x
    assertEquals(STR1, p.currentName());
    // assertSame(STR1, p.currentName());
    assertEquals(1, symbols1.size());
    assertEquals(JsonToken.VALUE_NUMBER_INT, p.nextToken());
    assertEquals(JsonToken.FIELD_NAME, p.nextToken());
    assertEquals("foobar", p.currentName());
    assertEquals(2, symbols1.size());
    assertEquals(JsonToken.VALUE_NUMBER_INT, p.nextToken());
    assertEquals(JsonToken.FIELD_NAME, p.nextToken());
    assertEquals("longername", p.currentName());
    assertEquals(3, symbols1.size());
    assertEquals(JsonToken.VALUE_NUMBER_INT, p.nextToken());
    assertEquals(JsonToken.END_OBJECT, p.nextToken());
    assertNull(p.nextToken());
    assertEquals(3, symbols1.size());
    p.close();
    // but let's verify that symbol table gets reused properly
    p = asyncForBytes(f, 5, doc, 0);
    final ByteQuadsCanonicalizer symbols2 = ((NonBlockingJsonParserBase) p.parser()).symbolTableForTests();
    // symbol tables are not reused, but contents are:
    assertNotSame(symbols1, symbols2);
    assertEquals(3, symbols2.size());
    assertEquals(JsonToken.START_OBJECT, p.nextToken());
    assertEquals(JsonToken.FIELD_NAME, p.nextToken());
    // field names are interned:
    assertEquals(STR1, p.currentName());
    assertEquals(3, symbols2.size());
    assertEquals(JsonToken.VALUE_NUMBER_INT, p.nextToken());
    assertEquals(JsonToken.FIELD_NAME, p.nextToken());
    assertEquals("foobar", p.currentName());
    assertEquals(3, symbols2.size());
    assertEquals(JsonToken.VALUE_NUMBER_INT, p.nextToken());
    assertEquals(JsonToken.FIELD_NAME, p.nextToken());
    assertEquals("longername", p.currentName());
    assertEquals(3, symbols2.size());
    assertEquals(JsonToken.VALUE_NUMBER_INT, p.nextToken());
    assertEquals(JsonToken.END_OBJECT, p.nextToken());
    assertNull(p.nextToken());
    assertEquals(3, symbols2.size());
    p.close();
    assertEquals(3, symbols2.size());
    p.close();
}
Also used : AsyncReaderWrapper(com.fasterxml.jackson.core.testsupport.AsyncReaderWrapper) JsonFactory(com.fasterxml.jackson.core.json.JsonFactory) ByteQuadsCanonicalizer(com.fasterxml.jackson.core.sym.ByteQuadsCanonicalizer) NonBlockingJsonParserBase(com.fasterxml.jackson.core.json.async.NonBlockingJsonParserBase)

Aggregations

ByteQuadsCanonicalizer (com.fasterxml.jackson.core.sym.ByteQuadsCanonicalizer)13 BaseTest (com.fasterxml.jackson.core.BaseTest)8 IOContext (com.fasterxml.jackson.core.io.IOContext)8 Test (org.junit.Test)8 BufferRecycler (com.fasterxml.jackson.core.util.BufferRecycler)7 JsonFactory (com.fasterxml.jackson.core.json.JsonFactory)2 NonBlockingJsonParserBase (com.fasterxml.jackson.core.json.async.NonBlockingJsonParserBase)2 AsyncReaderWrapper (com.fasterxml.jackson.core.testsupport.AsyncReaderWrapper)2 JsonToken (com.fasterxml.jackson.core.JsonToken)1 NonBlockingJsonParser (com.fasterxml.jackson.core.json.async.NonBlockingJsonParser)1 ByteArrayBuilder (com.fasterxml.jackson.core.util.ByteArrayBuilder)1