Search in sources :

Example 6 with com.amazon.ion.impl._Private_IonBinaryWriterBuilder

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

the class IonBinaryWriterBuilderTest method testInitialSymtab.

// -------------------------------------------------------------------------
@Test
public void testInitialSymtab() throws IOException {
    SymbolTable sst = _Private_Utils.systemSymtab(1);
    SymbolTable lst0 = Symtabs.localSymbolTableFactory().newLocalSymtab(sst);
    lst0.intern("hello");
    _Private_IonBinaryWriterBuilder b = _Private_IonBinaryWriterBuilder.standard();
    b.setInitialSymbolTable(lst0);
    assertSame(lst0, b.getInitialSymbolTable());
    OutputStream out = new ByteArrayOutputStream();
    IonWriter writer = b.build(out);
    assertEquals(sst.getMaxId() + 1, writer.getSymbolTable().findSymbol("hello"));
    // Builder makes a copy of the symtab
    SymbolTable lst1 = writer.getSymbolTable();
    assertNotSame(lst0, lst1);
    assertSame(lst0, b.getInitialSymbolTable());
    // Second call to build, we get another copy.
    writer = b.build(out);
    SymbolTable lst2 = writer.getSymbolTable();
    assertNotSame(lst0, lst2);
    assertNotSame(lst1, lst2);
    writer.writeSymbol("addition");
    // Now the LST has been extended, so the builder should make a copy
    // with the original max_id.
    writer = b.build(out);
    SymbolTable lst3 = writer.getSymbolTable();
    assertEquals(sst.getMaxId() + 1, lst3.findSymbol("hello"));
    assertEquals(sst.getMaxId() + 1, lst3.getMaxId());
    assertNotSame(lst0, lst3);
    assertNotSame(lst1, lst3);
    assertNotSame(lst2, lst3);
    assertSame(lst0, b.getInitialSymbolTable());
}
Also used : com.amazon.ion.impl._Private_IonBinaryWriterBuilder(com.amazon.ion.impl._Private_IonBinaryWriterBuilder) OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) SymbolTable(com.amazon.ion.SymbolTable) IonWriter(com.amazon.ion.IonWriter) com.amazon.ion.impl._Private_IonWriter(com.amazon.ion.impl._Private_IonWriter) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Aggregations

com.amazon.ion.impl._Private_IonBinaryWriterBuilder (com.amazon.ion.impl._Private_IonBinaryWriterBuilder)6 Test (org.junit.Test)5 SymbolTable (com.amazon.ion.SymbolTable)3 IonWriter (com.amazon.ion.IonWriter)2 com.amazon.ion.impl._Private_IonWriter (com.amazon.ion.impl._Private_IonWriter)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 OutputStream (java.io.OutputStream)2 IonCatalog (com.amazon.ion.IonCatalog)1 IonSystem (com.amazon.ion.IonSystem)1