use of com.amazon.ion.IonDatagram in project ion-java by amzn.
the class IonWriterTestCase method testWriteValuesCopiesCurrentValue.
@Test
public void testWriteValuesCopiesCurrentValue() throws Exception {
String data = "1 2 3";
IonReader ir = system().newReader(data);
ir.next();
iw = makeWriter();
iw.writeValues(ir);
IonDatagram dg = reload();
assertEquals(loader().load(data), dg);
}
use of com.amazon.ion.IonDatagram in project ion-java by amzn.
the class IonWriterTestCase method reload.
/**
* Extracts bytes from the current writer and loads it into a datagram.
*/
@SuppressWarnings("unused")
protected IonDatagram reload() throws Exception {
byte[] bytes = outputByteArray();
IonDatagram dg;
if (// Edit for debugging
false) {
try {
// force all the classes to load to we can step
// into the next time we try this and actually
// see what's going on
dg = loader().load(bytes);
} catch (IonException e) {
// do nothing
}
}
dg = loader().load(bytes);
return dg;
}
use of com.amazon.ion.IonDatagram in project ion-java by amzn.
the class IonWriterTestCase method testWritingEmptySymtab.
@Test
public void testWritingEmptySymtab() throws Exception {
iw = makeWriter();
iw.addTypeAnnotation(ION_SYMBOL_TABLE);
iw.stepIn(IonType.STRUCT);
iw.stepOut();
iw.writeSymbol("foo");
iw.close();
IonDatagram dg = reload();
IonSymbol foo = (IonSymbol) dg.get(0);
assertEquals(0, foo.getTypeAnnotations().length);
}
use of com.amazon.ion.IonDatagram in project ion-java by amzn.
the class IonWriterTestCase method testWritingAnnotationWithBadSid.
@Test
public void testWritingAnnotationWithBadSid() throws Exception {
iw = makeWriter();
IonDatagram expected = system().newDatagram();
iw.setTypeAnnotationSymbols(newSymbolToken("a", 99));
// expected: the type annotation is written
iw.writeNull();
IonValue v = expected.add().newNull();
v.setTypeAnnotations("a");
assertEquals(expected, reload());
}
use of com.amazon.ion.IonDatagram in project ion-java by amzn.
the class OptimizedBinaryWriterSymbolTableTest method testOptimizedWriteValueSameLST1.
/**
* Writer's LST identical to Reader's - optimize.
*/
@Test
public void testOptimizedWriteValueSameLST1() throws Exception {
String readerLST = printLocalSymtab("amazon", "website");
byte[] source = encode(readerLST + "amazon website");
ir = makeReaderProxy(source);
iw = makeWriterWithLocalSymtab("amazon", "website");
// writer's symtab same as reader's
// amazon
checkWriteValueWithCompatibleSymtab();
// website
checkWriteValueWithCompatibleSymtab();
iw.close();
IonDatagram expected = loader().load("amazon website");
IonDatagram actual = loader().load(outputByteArray());
assertIonEquals(expected, actual);
}
Aggregations