use of com.amazon.ion.IonDatagram in project ion-java by amzn.
the class IonWriterTestCase method testWritingWithImports.
// =========================================================================
@Test
public void testWritingWithImports() throws Exception {
final int FRED_ID_OFFSET = systemMaxId();
final int GINGER_ID_OFFSET = FRED_ID_OFFSET + FRED_MAX_IDS[1];
SymbolTable fred1 = Symtabs.register("fred", 1, catalog());
SymbolTable ginger1 = Symtabs.register("ginger", 1, catalog());
iw = makeWriter(fred1, ginger1);
iw.writeSymbol("fred_2");
iw.writeSymbol("g1");
iw.writeSymbol("localSym");
byte[] bytes = outputByteArray();
IonDatagram dg = loader().load(bytes);
assertEquals(5, dg.systemSize());
IonValue f2sym = dg.systemGet(2);
IonValue g1sym = dg.systemGet(3);
IonValue local = dg.systemGet(4);
checkSymbol("fred_2", FRED_ID_OFFSET + 2, f2sym);
checkSymbol("g1", GINGER_ID_OFFSET + 1, g1sym);
checkSymbol("localSym", local);
SymbolTable symtab = f2sym.getSymbolTable();
assertSame(symtab, g1sym.getSymbolTable());
SymbolTable[] importedTables = symtab.getImportedTables();
assertEquals(2, importedTables.length);
assertSame(fred1, importedTables[0]);
assertSame(ginger1, importedTables[1]);
}
use of com.amazon.ion.IonDatagram in project ion-java by amzn.
the class IonWriterTestCase method testAnnotationNotSetToIvmOnStartOfStream.
@Test
public void testAnnotationNotSetToIvmOnStartOfStream() throws Exception {
iw = makeWriter();
IonDatagram expected = system().newDatagram();
IonValue value1 = oneValue("1");
value1.addTypeAnnotation("some_annot");
value1.writeTo(iw);
// Expect: an annotation on value1
expected.add(value1);
IonValue value2 = oneValue("2");
value2.writeTo(iw);
iw.close();
expected.add(value2);
IonAssert.assertIonEquals(expected, reload());
}
use of com.amazon.ion.IonDatagram in project ion-java by amzn.
the class IonWriterTestCase method testWritingDatagram.
// TODO amzn/ion-java/issues/8 Inconsistencies between writers
@Test
public void testWritingDatagram() throws Exception {
IonDatagram dg = loader().load("foo");
iw = makeWriter();
dg.writeTo(iw);
iw.writeValue(dg);
Iterator<IonValue> it = systemIterateOutput();
checkSymbol(SystemSymbols.ION_1_0, it.next());
if (myOutputForm != OutputForm.TEXT) {
checkAnnotation(SystemSymbols.ION_SYMBOL_TABLE, it.next());
}
// TODO amzn/ion-java#14
if (myOutputForm != OutputForm.TEXT) {
checkSymbol(null, 10, it.next());
} else {
checkSymbol("foo", it.next());
}
}
use of com.amazon.ion.IonDatagram in project ion-java by amzn.
the class IonWriterTestCase method testAnnotationNotSetToIvmAfterFinish.
@Test
public void testAnnotationNotSetToIvmAfterFinish() throws Exception {
iw = makeWriter();
IonDatagram expected = system().newDatagram();
IonValue value1 = oneValue("1");
value1.writeTo(iw);
// Resets the stream context, the next TLV that is written must behave
// as if it is preceded by an IVM, depending on the writer's config.
iw.finish();
expected.add(value1);
IonValue value2 = oneValue("2");
value2.addTypeAnnotation("some_annot");
value2.writeTo(iw);
iw.close();
// Expect: an annotation on value2
expected.add(value2);
IonAssert.assertIonEquals(expected, reload());
}
use of com.amazon.ion.IonDatagram in project ion-java by amzn.
the class IonWriterTestCase method testWriteIVMExplicitly.
@Test
public void testWriteIVMExplicitly() throws Exception {
iw = makeWriter();
iw.writeSymbol("foo");
((_Private_IonWriter) iw).writeIonVersionMarker();
iw.writeInt(1);
IonDatagram dg = reload();
assertEquals(2, dg.size());
}
Aggregations