Search in sources :

Example 16 with IonList

use of com.amazon.ion.IonList in project jackson-dataformats-binary by FasterXML.

the class DataBindWriteTest method initializeExpectedArray.

@Before
public void initializeExpectedArray() {
    expectedArray = ion.newDatagram();
    IonList list = ion.newEmptyList();
    list.add().newInt(1);
    list.add().newInt(2);
    list.add().newInt(3);
    expectedArray.add(list);
}
Also used : IonList(com.amazon.ion.IonList) Before(org.junit.Before)

Example 17 with IonList

use of com.amazon.ion.IonList in project ion-java by amzn.

the class SymbolTableStructCache method makeIonRepresentation.

/**
 * Create a new IonStruct representation of the symbol table.
 * @param factory the {@link ValueFactory} from which to construct the IonStruct.
 */
private void makeIonRepresentation(ValueFactory factory) {
    image = factory.newEmptyStruct();
    image.addTypeAnnotation(ION_SYMBOL_TABLE);
    if (importedTables.length > 0) {
        // The system symbol table may be the first import. If it is, skip it.
        int i = importedTables[0].isSystemTable() ? 1 : 0;
        if (i < importedTables.length) {
            IonList importsList = factory.newEmptyList();
            while (i < importedTables.length) {
                SymbolTable importedTable = importedTables[i];
                IonStruct importStruct = factory.newEmptyStruct();
                importStruct.add(NAME, factory.newString(importedTable.getName()));
                importStruct.add(VERSION, factory.newInt(importedTable.getVersion()));
                importStruct.add(MAX_ID, factory.newInt(importedTable.getMaxId()));
                importsList.add(importStruct);
                i++;
            }
            image.add(IMPORTS, importsList);
        }
    }
    if (symbolTable.getMaxId() > symbolTable.getImportedMaxId()) {
        Iterator<String> localSymbolIterator = symbolTable.iterateDeclaredSymbolNames();
        int sid = symbolTable.getImportedMaxId() + 1;
        while (localSymbolIterator.hasNext()) {
            addSymbol(localSymbolIterator.next(), sid);
            sid++;
        }
    }
}
Also used : IonStruct(com.amazon.ion.IonStruct) IonList(com.amazon.ion.IonList) SymbolTable(com.amazon.ion.SymbolTable)

Example 18 with IonList

use of com.amazon.ion.IonList in project ion-java by amzn.

the class _Private_CurriedValueFactory method newList.

public IonList newList(IonSequence firstChild) throws ContainedValueException, NullPointerException {
    IonList v = myFactory.newList(firstChild);
    handle(v);
    return v;
}
Also used : IonList(com.amazon.ion.IonList)

Example 19 with IonList

use of com.amazon.ion.IonList in project ion-java by amzn.

the class OptimizedBinaryWriterLengthPatchingTest method testOptimizedWriteLengthPatching.

/**
 * Tests that the internal implementation of binary {@link IonWriter}'s
 * patching mechanism is correct.
 *
 * @see IonWriterSystemBinary
 */
@Test
public void testOptimizedWriteLengthPatching() throws Exception {
    iw = makeWriter();
    // The expected datagram - as values are copied to the IonWriter, we
    // book-keep the values written so as to do an equality check at the end.
    IonDatagram expected = system().newDatagram();
    // === top level ===
    writeAndAddTypeDescLengthVariants(expected);
    // === nested list ===
    iw.stepIn(IonType.LIST);
    IonList expectedNestedList = expected.add().newEmptyList();
    {
        writeAndAddTypeDescLengthVariants(expectedNestedList);
    }
    iw.stepOut();
    // === nested sexp ===
    iw.stepIn(IonType.SEXP);
    IonSexp expectedNestedSexp = expected.add().newEmptySexp();
    {
        writeAndAddTypeDescLengthVariants(expectedNestedSexp);
    }
    iw.stepOut();
    // === nested struct ===
    iw.stepIn(IonType.STRUCT);
    IonStruct expectedNestedStruct = expected.add().newEmptyStruct();
    {
        writeAndAddTypeDescLengthVariants(expectedNestedStruct);
    }
    iw.stepOut();
    // === deeply nested list ===
    iw.stepIn(IonType.LIST);
    IonList nestedList1 = expected.add().newEmptyList();
    {
        writeAndAddTypeDescLengthVariants(nestedList1);
        iw.stepIn(IonType.LIST);
        {
            IonList nestedList2 = nestedList1.add().newEmptyList();
            writeAndAddTypeDescLengthVariants(nestedList2);
        }
        iw.stepOut();
    }
    iw.stepOut();
    IonDatagram actual = loader().load(outputByteArray());
    assertIonEquals(expected, actual);
}
Also used : IonStruct(com.amazon.ion.IonStruct) IonSexp(com.amazon.ion.IonSexp) IonDatagram(com.amazon.ion.IonDatagram) IonList(com.amazon.ion.IonList) Test(org.junit.Test)

Example 20 with IonList

use of com.amazon.ion.IonList in project ion-java by amzn.

the class SymbolTableTest method checkFirstImport.

static void checkFirstImport(String name, int version, String[] expectedSymbols, IonStruct symtab) throws IOException {
    IonList imports = (IonList) symtab.get(SystemSymbols.IMPORTS);
    IonStruct i0 = (IonStruct) imports.get(0);
    checkString(name, i0.get(SystemSymbols.NAME));
    checkInt(version, i0.get(SystemSymbols.VERSION));
    checkInt(expectedSymbols.length, i0.get(SystemSymbols.MAX_ID));
}
Also used : IonStruct(com.amazon.ion.IonStruct) IonList(com.amazon.ion.IonList)

Aggregations

IonList (com.amazon.ion.IonList)28 IonStruct (com.amazon.ion.IonStruct)13 Test (org.junit.Test)10 SymbolTable (com.amazon.ion.SymbolTable)5 IonDatagram (com.amazon.ion.IonDatagram)4 IonFloat (com.amazon.ion.IonFloat)3 IonReader (com.amazon.ion.IonReader)3 IonSexp (com.amazon.ion.IonSexp)3 IonString (com.amazon.ion.IonString)3 IonSymbol (com.amazon.ion.IonSymbol)3 IonBlob (com.amazon.ion.IonBlob)2 IonClob (com.amazon.ion.IonClob)2 IonTimestamp (com.amazon.ion.IonTimestamp)2 IonValue (com.amazon.ion.IonValue)2 BlobTest (com.amazon.ion.BlobTest)1 ClobTest (com.amazon.ion.ClobTest)1 IntTest (com.amazon.ion.IntTest)1 IonBool (com.amazon.ion.IonBool)1 IonDecimal (com.amazon.ion.IonDecimal)1 IonException (com.amazon.ion.IonException)1