use of com.amazon.ion.IonDatagram in project ion-java by amzn.
the class IonWriterTestCase method testWritingWithSystemImport.
@Test
public void testWritingWithSystemImport() throws Exception {
final int FRED_ID_OFFSET = systemMaxId();
final int LOCAL_ID_OFFSET = FRED_ID_OFFSET + FRED_MAX_IDS[1];
SymbolTable fred1 = Symtabs.register("fred", 1, catalog());
iw = makeWriter(system().getSystemSymbolTable(), fred1);
iw.writeSymbol("fred_2");
iw.writeSymbol("localSym");
byte[] bytes = outputByteArray();
IonDatagram dg = loader().load(bytes);
assertEquals(4, dg.systemSize());
IonValue f2sym = dg.systemGet(2);
IonValue local = dg.systemGet(3);
checkSymbol("fred_2", FRED_ID_OFFSET + 2, f2sym);
checkSymbol("localSym", local);
SymbolTable symtab = f2sym.getSymbolTable();
assertSame(symtab, local.getSymbolTable());
SymbolTable[] importedTables = symtab.getImportedTables();
assertEquals(1, importedTables.length);
assertSame(fred1, importedTables[0]);
}
use of com.amazon.ion.IonDatagram in project ion-java by amzn.
the class IonWriterTestCase method testWritingClearedAnnotations.
/**
* Test case to ensure that {@link IonWriter#setTypeAnnotations(String...)}
* and {@link IonWriter#setTypeAnnotationSymbols(SymbolToken...)} clearing
* of type annotations behavior is correct.
*/
@Test
public void testWritingClearedAnnotations() throws Exception {
iw = makeWriter();
IonDatagram expected = system().newDatagram();
// ===== Test on IonWriter.setTypeAnnotationSymbols(...) =====
// empty SymbolToken[]
iw.setTypeAnnotationSymbols(new SymbolToken[0]);
iw.writeNull();
IonValue v = expected.add().newNull();
v.clearTypeAnnotations();
// null SymbolToken[]
iw.setTypeAnnotationSymbols((SymbolToken[]) null);
iw.writeNull();
v = expected.add().newNull();
v.clearTypeAnnotations();
iw.addTypeAnnotation("b");
// empty SymbolToken[]
iw.setTypeAnnotationSymbols(new SymbolToken[0]);
// expected: the pending "b" annotation is cleared
iw.writeNull();
v = expected.add().newNull();
v.clearTypeAnnotations();
iw.addTypeAnnotation("b");
// null SymbolToken[]
iw.setTypeAnnotationSymbols((SymbolToken[]) null);
// expected: the pending "b" annotation is cleared
iw.writeNull();
v = expected.add().newNull();
v.clearTypeAnnotations();
// ===== Test on IonWriter.setTypeAnnotations(...) =====
// empty String[]
iw.setTypeAnnotations(new String[0]);
iw.writeNull();
v = expected.add().newNull();
v.clearTypeAnnotations();
// null String[]
iw.setTypeAnnotations((String[]) null);
iw.writeNull();
v = expected.add().newNull();
v.clearTypeAnnotations();
iw.addTypeAnnotation("b");
// empty String[]
iw.setTypeAnnotations(new String[0]);
// expected: the pending "b" annotation is cleared
iw.writeNull();
v = expected.add().newNull();
v.clearTypeAnnotations();
iw.addTypeAnnotation("b");
// null String[]
iw.setTypeAnnotations((String[]) null);
// expected: the pending "b" annotation is cleared
iw.writeNull();
v = expected.add().newNull();
v.clearTypeAnnotations();
assertEquals(expected, reload());
}
use of com.amazon.ion.IonDatagram in project ion-java by amzn.
the class IonWriterTestCase method testWriteValuesWithSymtab.
@Test
public void testWriteValuesWithSymtab() throws Exception {
SymbolTable fredSymtab = Symtabs.register(Symtabs.FRED_NAME, 1, catalog());
SymbolTable gingerSymtab = Symtabs.register(Symtabs.GINGER_NAME, 1, catalog());
String gingerSym = gingerSymtab.findKnownSymbol(1);
// First setup some data to be copied.
IonDatagram dg = system().newDatagram(gingerSymtab);
dg.add().newSymbol(gingerSym);
IonReader r = system().newReader(dg.getBytes());
// Now copy that data into a non-top-level context
iw = makeWriter(fredSymtab);
iw.stepIn(IonType.LIST);
iw.writeValues(r);
iw.stepOut();
IonDatagram result = reload();
IonList l = (IonList) result.get(0);
assertEquals(1, l.size());
IonSymbol s = (IonSymbol) l.get(0);
// Should've assigned a new SID
checkSymbol(gingerSym, s);
}
use of com.amazon.ion.IonDatagram in project ion-java by amzn.
the class IonWriterTestCase method testWritingAnnotations.
@Test
public void testWritingAnnotations() throws Exception {
iw = makeWriter();
IonDatagram expected = system().newDatagram();
iw.addTypeAnnotation("a");
iw.writeNull();
IonValue v = expected.add().newNull();
v.addTypeAnnotation("a");
iw.addTypeAnnotation("b");
iw.addTypeAnnotation("c");
iw.writeNull();
v = expected.add().newNull();
v.addTypeAnnotation("b");
v.addTypeAnnotation("c");
iw.addTypeAnnotation("b");
iw.addTypeAnnotation("b");
iw.writeNull();
v = expected.add().newNull();
v.setTypeAnnotations("b", "b");
iw.setTypeAnnotations("b", "b");
iw.writeNull();
v = expected.add().newNull();
v.setTypeAnnotations("b", "b");
iw.addTypeAnnotation("b");
iw.setTypeAnnotations("c", "d");
iw.writeNull();
v = expected.add().newNull();
v.setTypeAnnotations("c", "d");
iw.addTypeAnnotation("b");
iw.setTypeAnnotations(new String[0]);
iw.writeNull();
v = expected.add().newNull();
v.clearTypeAnnotations();
iw.addTypeAnnotation("b");
iw.setTypeAnnotations((String[]) null);
iw.writeNull();
v = expected.add().newNull();
v.clearTypeAnnotations();
iw.addTypeAnnotation("b");
iw.setTypeAnnotations();
iw.writeNull();
v = expected.add().newNull();
v.clearTypeAnnotations();
iw.addTypeAnnotation("b");
iw.setTypeAnnotationSymbols(new SymbolToken[0]);
iw.writeNull();
v = expected.add().newNull();
v.clearTypeAnnotations();
iw.addTypeAnnotation("b");
iw.setTypeAnnotationSymbols((SymbolToken[]) null);
iw.writeNull();
v = expected.add().newNull();
v.clearTypeAnnotations();
iw.addTypeAnnotation("b");
iw.setTypeAnnotationSymbols();
iw.writeNull();
v = expected.add().newNull();
v.clearTypeAnnotations();
assertEquals(expected, reload());
}
use of com.amazon.ion.IonDatagram in project ion-java by amzn.
the class IonWriterTestCase method testWritingDeepNestedList.
@Test
public void testWritingDeepNestedList() throws Exception {
IonDatagram dg = loader().load("[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]");
iw = makeWriter();
dg.writeTo(iw);
iw.writeValue(dg);
}
Aggregations