Search in sources :

Example 6 with ByteQuadsCanonicalizer

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

the class UTF8DataInputJsonParserTest method testParseEscapedNameThrowsArrayIndexOutOfBoundsException.

@Test
public void testParseEscapedNameThrowsArrayIndexOutOfBoundsException() throws IOException {
    IOContext ioContext = new IOContext((BufferRecycler) null, null, false);
    PipedOutputStream pipedOutputStream = new PipedOutputStream();
    PipedInputStream pipedInputStream = new PipedInputStream(pipedOutputStream, 131);
    DataInputStream dataInputStream = new DataInputStream(pipedInputStream);
    ByteQuadsCanonicalizer byteQuadsCanonicalizer = ByteQuadsCanonicalizer.createRoot();
    UTF8DataInputJsonParser uTF8DataInputJsonParser = new UTF8DataInputJsonParser(ObjectReadContext.empty(), ioContext, 131, dataInputStream, byteQuadsCanonicalizer, (byte) 57);
    int[] intArray = new int[3];
    try {
        uTF8DataInputJsonParser.parseEscapedName(intArray, 56, (byte) 72, (byte) 127, (byte) 57);
        fail("Expecting exception: ArrayIndexOutOfBoundsException");
    } catch (ArrayIndexOutOfBoundsException e) {
        assertEquals(UTF8DataInputJsonParser.class.getName(), e.getStackTrace()[0].getClassName());
    }
}
Also used : 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 ByteQuadsCanonicalizer

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

the class AsyncParserNamesTest method testSymbolTableWithIntern.

public void testSymbolTableWithIntern() throws IOException {
    JsonFactory internF = JsonFactory.builder().enable(TokenStreamFactory.Feature.INTERN_FIELD_NAMES).build();
    final String STR1 = "a";
    byte[] doc = _jsonDoc("{ " + quote(STR1) + ":1, \"foobar\":2, \"longername\":3 }");
    AsyncReaderWrapper p = asyncForBytes(internF, 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());
    assertSame(STR1, p.currentName());
    assertEquals(1, symbols1.size());
    assertEquals(JsonToken.VALUE_NUMBER_INT, p.nextToken());
    assertEquals(JsonToken.FIELD_NAME, p.nextToken());
    assertSame("foobar", p.currentName());
    assertEquals(2, symbols1.size());
    assertEquals(JsonToken.VALUE_NUMBER_INT, p.nextToken());
    assertEquals(JsonToken.FIELD_NAME, p.nextToken());
    assertSame("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();
}
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)

Example 8 with ByteQuadsCanonicalizer

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

the class JsonFactory method _createParser.

/**
     * @since 2.8
     */
protected JsonParser _createParser(DataInput input, IOContext ctxt) throws IOException {
    // 13-May-2016, tatu: Need to take care not to accidentally create JSON parser for
    //   non-JSON input. So, bit unclean but...
    String format = getFormatName();
    if (format != FORMAT_NAME_JSON) {
        // NOTE: only ensure override; full equality NOT needed
        throw new UnsupportedOperationException(String.format("InputData source not (yet?) support for this format (%s)", format));
    }
    // Also: while we can't do full bootstrapping (due to read-ahead limitations), should
    // at least handle possible UTF-8 BOM
    int firstByte = ByteSourceJsonBootstrapper.skipUTF8BOM(input);
    ByteQuadsCanonicalizer can = _byteSymbolCanonicalizer.makeChild(_factoryFeatures);
    return new UTF8DataInputJsonParser(ctxt, _parserFeatures, input, _objectCodec, can, firstByte);
}
Also used : ByteQuadsCanonicalizer(com.fasterxml.jackson.core.sym.ByteQuadsCanonicalizer)

Example 9 with ByteQuadsCanonicalizer

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

the class UTF8DataInputJsonParserTest method test_readBinaryThrowsNullPointerException.

@Test
public void test_readBinaryThrowsNullPointerException() throws IOException {
    byte[] byteArray = new byte[5];
    byteArray[4] = (byte) 43;
    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, 500, dataInputStream, byteQuadsCanonicalizer, 1);
    try {
        uTF8DataInputJsonParser._readBinary(null, null, byteArray);
        fail("Expecting exception: NullPointerException");
    } catch (NullPointerException e) {
        assertEquals(UTF8DataInputJsonParser.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 10 with ByteQuadsCanonicalizer

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

the class UTF8DataInputJsonParserTest method test_decodeBase64ThrowsEOFException.

@Test
public void test_decodeBase64ThrowsEOFException() throws IOException {
    IOContext ioContext = new IOContext(new BufferRecycler(), this, true);
    byte[] byteArray = new byte[5];
    InputStream byteArrayInputStream = new ByteArrayInputStream(byteArray);
    DataInputStream dataInputStream = new DataInputStream(byteArrayInputStream);
    ByteQuadsCanonicalizer byteQuadsCanonicalizer = ByteQuadsCanonicalizer.createRoot();
    UTF8DataInputJsonParser uTF8DataInputJsonParser = new UTF8DataInputJsonParser(ObjectReadContext.empty(), ioContext, (byte) 26, dataInputStream, byteQuadsCanonicalizer, 3);
    try {
        uTF8DataInputJsonParser._decodeBase64(null);
        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)

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