Search in sources :

Example 51 with IonStruct

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

the class SymbolTableTest method writeIonRep.

IonStruct writeIonRep(SymbolTable st) throws IOException {
    IonList container = system().newEmptyList();
    st.writeTo(system().newTreeWriter(container));
    IonStruct stStruct = (IonStruct) container.get(0);
    return stStruct;
}
Also used : IonStruct(com.amazon.ion.IonStruct) IonList(com.amazon.ion.IonList)

Example 52 with IonStruct

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

the class SymbolTableTest method checkFirstImport.

SymbolTable checkFirstImport(String name, int version, String[] expectedSymbols, SymbolTable st) throws IOException {
    IonStruct stStruct = writeIonRep(st);
    checkFirstImport(name, version, expectedSymbols, stStruct);
    SymbolTable importedTable = st.getImportedTables()[0];
    checkSharedTable(name, version, expectedSymbols, importedTable);
    return importedTable;
}
Also used : IonStruct(com.amazon.ion.IonStruct) SymbolTable(com.amazon.ion.SymbolTable)

Example 53 with IonStruct

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

the class SymbolTableTest method insert_local_symbol_table.

private void insert_local_symbol_table(IonDatagram data) {
    IonStruct local_symbol_table = system().newEmptyStruct();
    local_symbol_table.addTypeAnnotation("$ion_symbol_table");
    IonList symbols = system().newEmptyList();
    symbols.add(system().newString("one"));
    symbols.add(system().newString("two"));
    local_symbol_table.add("symbols", symbols);
    data.add(local_symbol_table);
}
Also used : IonStruct(com.amazon.ion.IonStruct) IonList(com.amazon.ion.IonList)

Example 54 with IonStruct

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

the class SymbolTableTest method testInjectingMaxIdIntoImport.

@Test
public // TODO implement
void testInjectingMaxIdIntoImport() {
    SymbolTable importedTable = registerImportedV1();
    String text = LocalSymbolTablePrefix + "{" + "  imports:[{name:'''imported''',version:1}],\n" + "}\n" + "null";
    IonDatagram dg = loader().load(text);
    SymbolTable symbolTable = dg.get(0).getSymbolTable();
    checkLocalTable(symbolTable);
    SymbolTable[] imported = symbolTable.getImportedTables();
    assertEquals(1, imported.length);
    assertSame(importedTable, imported[0]);
    // Check that the encoded table has max_id on import
    byte[] binary = dg.getBytes();
    dg = loader().load(binary);
    IonStruct symtabStruct = (IonStruct) dg.systemGet(1);
    IonList imports = (IonList) symtabStruct.get("imports");
    IonStruct importStruct = (IonStruct) imports.get(0);
    checkString("imported", importStruct.get("name"));
    IonValue maxIdValue = importStruct.get("max_id");
    assertNotNull("max_id wasn't injected into import", maxIdValue);
    checkInt(IMPORTED_1_MAX_ID, maxIdValue);
}
Also used : IonValue(com.amazon.ion.IonValue) IonStruct(com.amazon.ion.IonStruct) IonDatagram(com.amazon.ion.IonDatagram) IonList(com.amazon.ion.IonList) SymbolTable(com.amazon.ion.SymbolTable) Test(org.junit.Test)

Example 55 with IonStruct

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

the class Symtabs method registerTables.

private static int[] registerTables(String[] serializedTables) {
    int[] maxIds = new int[serializedTables.length];
    _Private_IonSystem system = (_Private_IonSystem) IonSystemBuilder.standard().withCatalog(CATALOG).build();
    for (int i = 1; i < serializedTables.length; i++) {
        String serialized = serializedTables[i];
        IonStruct st = (IonStruct) system.singleValue(serialized);
        SymbolTable shared = system.newSharedSymbolTable(st);
        CATALOG.putTable(shared);
        maxIds[i] = shared.getMaxId();
    }
    return maxIds;
}
Also used : IonStruct(com.amazon.ion.IonStruct) SymbolTable(com.amazon.ion.SymbolTable) IonTextUtils.printString(com.amazon.ion.util.IonTextUtils.printString)

Aggregations

IonStruct (com.amazon.ion.IonStruct)68 Test (org.junit.Test)28 IonValue (com.amazon.ion.IonValue)18 IonDatagram (com.amazon.ion.IonDatagram)13 IonList (com.amazon.ion.IonList)13 IonReader (com.amazon.ion.IonReader)13 SymbolTable (com.amazon.ion.SymbolTable)13 IOException (java.io.IOException)8 IonString (com.amazon.ion.IonString)7 IonSystem (com.amazon.ion.IonSystem)6 IonException (com.amazon.ion.IonException)5 IonSequence (com.amazon.ion.IonSequence)5 IonType (com.amazon.ion.IonType)5 IonFloat (com.amazon.ion.IonFloat)4 IonSymbol (com.amazon.ion.IonSymbol)4 IonTimestamp (com.amazon.ion.IonTimestamp)4 IonWriter (com.amazon.ion.IonWriter)4 SymbolToken (com.amazon.ion.SymbolToken)4 ArrayList (java.util.ArrayList)4 IonBlob (com.amazon.ion.IonBlob)3