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());
}
Aggregations