Search in sources :

Example 21 with IonList

use of com.amazon.ion.IonList 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 22 with IonList

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

the class SymbolTableTest method serialize.

public IonList serialize(final SymbolTable table) throws IOException {
    final IonList container = system().newEmptyList();
    table.writeTo(system().newWriter(container));
    return container;
}
Also used : IonList(com.amazon.ion.IonList)

Example 23 with IonList

use of com.amazon.ion.IonList 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 24 with IonList

use of com.amazon.ion.IonList 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 25 with IonList

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

the class TreeReaderTest method testModificationDuringRead.

@Test
public void testModificationDuringRead() {
    IonList list = system().newEmptyList();
    list.add().newString("abc");
    list.add().newString("def");
    in = system().newReader(list);
    assertEquals(IonType.LIST, in.next());
    in.stepIn();
    assertEquals(IonType.STRING, in.next());
    // Violate the contract by modifying the value.
    list.remove(0);
    // Since the value was modified while it was being written, the result of the following is undefined. But
    // one thing is for sure: it should not cause an infinite loop.
    in.next();
}
Also used : IonList(com.amazon.ion.IonList) Test(org.junit.Test)

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