Search in sources :

Example 1 with IonMutableCatalog

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

the class IonManagedBinaryWriterTestCase method createWriter.

@Override
protected IonWriter createWriter(final OutputStream out) throws IOException {
    final IonMutableCatalog catalog = ((IonMutableCatalog) system().getCatalog());
    final List<SymbolTable> symbolTables = new ArrayList<SymbolTable>();
    int i = 1;
    for (final List<String> symbols : SHARED_SYMBOLS) {
        final SymbolTable table = system().newSharedSymbolTable("test_" + (i++), 1, symbols.iterator());
        symbolTables.add(table);
        catalog.putTable(table);
    }
    final _Private_IonManagedBinaryWriterBuilder builder = _Private_IonManagedBinaryWriterBuilder.create(_Private_IonManagedBinaryWriterBuilder.AllocatorMode.POOLED).withImports(importedSymbolResolverMode, symbolTables).withPreallocationMode(preallocationMode).withFloatBinary32Enabled();
    if (lstAppendMode.isEnabled()) {
        builder.withLocalSymbolTableAppendEnabled();
    } else {
        builder.withLocalSymbolTableAppendDisabled();
    }
    final IonWriter writer = builder.newWriter(out);
    final SymbolTable locals = writer.getSymbolTable();
    assertEquals(14, locals.getImportedMaxId());
    return writer;
}
Also used : ArrayList(java.util.ArrayList) SymbolTable(com.amazon.ion.SymbolTable) IonWriter(com.amazon.ion.IonWriter) IonMutableCatalog(com.amazon.ion.IonMutableCatalog)

Example 2 with IonMutableCatalog

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

the class SymbolTableTest method testDupLocalSymbolOnDatagram.

@Test
public void testDupLocalSymbolOnDatagram() throws Exception {
    final IonSystem ion1 = system();
    final SymbolTable st = ion1.newSharedSymbolTable("foobar", 1, Arrays.asList("s1").iterator());
    final IonMutableCatalog cat = new SimpleCatalog();
    cat.putTable(st);
    // amzn/ion-java/issues/46 has the datagram producing something like:
    // $ion_1_0 $ion_symbol_table::{imports:[{name: "foobar", version: 1, max_id: 1}], symbols: ["s1", "l1"]} $11 $12
    // local table should not have "s1", user values should be $10 $11
    IonDatagram dg = ion1.newDatagram(st);
    dg.add().newSymbol("s1");
    dg.add().newSymbol("l1");
    final IonSystem ion2 = newSystem(cat);
    dg = ion2.getLoader().load(dg.getBytes());
    checkSymbol("s1", 10, dg.get(0));
    checkSymbol("l1", 11, dg.get(1));
}
Also used : SimpleCatalog(com.amazon.ion.system.SimpleCatalog) IonSystem(com.amazon.ion.IonSystem) IonDatagram(com.amazon.ion.IonDatagram) SymbolTable(com.amazon.ion.SymbolTable) IonMutableCatalog(com.amazon.ion.IonMutableCatalog) Test(org.junit.Test)

Aggregations

IonMutableCatalog (com.amazon.ion.IonMutableCatalog)2 SymbolTable (com.amazon.ion.SymbolTable)2 IonDatagram (com.amazon.ion.IonDatagram)1 IonSystem (com.amazon.ion.IonSystem)1 IonWriter (com.amazon.ion.IonWriter)1 SimpleCatalog (com.amazon.ion.system.SimpleCatalog)1 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1