use of com.amazon.ion.IonDatagram in project ion-java by amzn.
the class TextWriterTest method testWritingJsonLongClobs.
@Test
public void testWritingJsonLongClobs() throws Exception {
options = IonTextWriterBuilder.json();
options.setInitialIvmHandling(SUPPRESS);
options.setLongStringThreshold(4);
// Cannot call expectRendering as the input to reload() would be Json rather than Ion
// test 1
IonDatagram dg = system().newDatagram();
dg.add().newClob(new byte[] { 'a', '"', '\'', '\n' });
// expectRendering
iw = makeWriter();
dg.writeTo(iw);
IonDatagram reloaded = loader().load("{{\"a\\\"'\\n\"}}");
assertEquals(dg, reloaded);
String actual = outputString();
assertEquals("\"a\\\"'\\n\"", actual);
// test 2
dg.clear();
dg.add().newClob(new byte[] { 'a', '"', '\'', '\n', 'c', 0x7F });
// expectRendering
iw = makeWriter();
dg.writeTo(iw);
reloaded = loader().load("{{'''a\"\\'\nc\\x7f'''}}");
assertEquals(dg, reloaded);
actual = outputString();
assertEquals("\"a\\\"'\\nc\\u007f\"", actual);
}
use of com.amazon.ion.IonDatagram in project ion-java by amzn.
the class TextWriterTest method testNewLineTypesWithStandardPrinting.
@Test
public void testNewLineTypesWithStandardPrinting() {
for (IonTextWriterBuilder.NewLineType nlt : IonTextWriterBuilder.NewLineType.values()) {
String expected = String.format("\"Foo\"%sBar%<s(1 2 3)%<s[4,5,6]", nlt.getCharSequence());
IonTextWriterBuilder writerBuilder = IonTextWriterBuilder.standard().withInitialIvmHandling(SUPPRESS).withWriteTopLevelValuesOnNewLines(true).withNewLineType(nlt);
IonDatagram dg = system().newDatagram();
dg.add().newString("Foo");
dg.add().newSymbol("Bar");
dg.add().newSexp(new int[] { 1, 2, 3 });
dg.add().newList(new int[] { 4, 5, 6 });
StringBuilder sb = new StringBuilder();
IonWriter writer = writerBuilder.build(sb);
dg.writeTo(writer);
assertEquals(expected, sb.toString());
}
}
use of com.amazon.ion.IonDatagram in project ion-java by amzn.
the class ValueWriterTest method testWriteValuesWithSymtabIntoContainer.
// TODO more thorough testing that you can't output from DOM w/ bad text
@Test
public void testWriteValuesWithSymtabIntoContainer() throws Exception {
myOutputInList = true;
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.writeValues(r);
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, systemMaxId() + Symtabs.FRED_MAX_IDS[1] + 1, s);
}
use of com.amazon.ion.IonDatagram in project ion-java by amzn.
the class IonManagedBinaryWriterTest method testManuallyWriteLSTAppendWithSymbolsFirst.
@Test
public void testManuallyWriteLSTAppendWithSymbolsFirst() throws Exception {
writer.writeSymbol("taco");
writer.addTypeAnnotation("$ion_symbol_table");
writer.stepIn(IonType.STRUCT);
writer.setFieldName("symbols");
writer.stepIn(IonType.LIST);
writer.writeString("burrito");
writer.stepOut();
writer.setFieldName("imports");
writer.writeSymbol("$ion_symbol_table");
writer.stepOut();
writer.writeSymbol("burrito");
writer.finish();
IonReader reader = system().newReader(writer.getBytes());
reader.next();
assertEquals(reader.getSymbolTable().findSymbol("taco"), 15);
assertEquals(reader.getSymbolTable().findSymbol("burrito"), lstAppendMode.isEnabled() ? -1 : 16);
reader.next();
assertEquals(reader.getSymbolTable().findSymbol("taco"), 15);
assertEquals(reader.getSymbolTable().findSymbol("burrito"), 16);
assertNull(reader.next());
IonDatagram dg = system().getLoader().load(writer.getBytes());
assertEquals(2, dg.size());
assertEquals("taco", ((IonSymbol) dg.get(0)).stringValue());
assertEquals("burrito", ((IonSymbol) dg.get(1)).stringValue());
}
use of com.amazon.ion.IonDatagram in project ion-java by amzn.
the class IonWriterTestCase method testWritingSymtabWithExtraAnnotations.
// TODO amzn/ion-java/issues/15
@Test
// TODO amzn/ion-java/issues/15
@Ignore
public void testWritingSymtabWithExtraAnnotations() throws Exception {
String[] annotations = new String[] { ION_SYMBOL_TABLE, ION_SYMBOL_TABLE };
iw = makeWriter();
iw.setTypeAnnotations(annotations);
iw.stepIn(IonType.STRUCT);
iw.stepOut();
iw.writeSymbol("foo");
iw.close();
IonDatagram dg = reload();
IonStruct v = (IonStruct) dg.systemGet(1);
Assert.assertArrayEquals(annotations, v.getTypeAnnotations());
}
Aggregations