use of com.amazon.ion.system.IonTextWriterBuilder in project ion-java by amzn.
the class RoundTripTest method testTextWriterLongStrings.
@Test
public void testTextWriterLongStrings() throws Exception {
IonTextWriterBuilder b = IonTextWriterBuilder.standard().withLongStringThreshold(1);
checkTextOutput(b);
}
use of com.amazon.ion.system.IonTextWriterBuilder in project ion-java by amzn.
the class TextWriterTest method testWritingTopLevelValuesOnNewLinesShouldHaveNoEffectWithPrettyPrint.
@Test
public void testWritingTopLevelValuesOnNewLinesShouldHaveNoEffectWithPrettyPrint() {
// Setting top-level newlines to false should have no effect when pretty printing.
IonTextWriterBuilder writerBuilder = IonTextWriterBuilder.standard().withInitialIvmHandling(SUPPRESS).withWriteTopLevelValuesOnNewLines(false).withPrettyPrinting().withNewLineType(IonTextWriterBuilder.NewLineType.LF);
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("\n\"Foo\"\nBar\n(\n 1\n 2\n 3\n)\n[\n 4,\n 5,\n 6\n]", sb.toString());
}
use of com.amazon.ion.system.IonTextWriterBuilder in project ion-java by amzn.
the class TextWriterTest method testWritingTopLevelValuesOnNewLinesWithoutPrettyPrint.
@Test
public void testWritingTopLevelValuesOnNewLinesWithoutPrettyPrint() {
IonTextWriterBuilder writerBuilder = IonTextWriterBuilder.standard().withInitialIvmHandling(SUPPRESS).withWriteTopLevelValuesOnNewLines(true).withNewLineType(IonTextWriterBuilder.NewLineType.LF);
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 });
IonStruct struct = dg.add().newEmptyStruct();
struct.add("def").newInt(42);
struct.addTypeAnnotation("abc");
StringBuilder sb = new StringBuilder();
IonWriter writer = writerBuilder.build(sb);
dg.writeTo(writer);
assertEquals("\"Foo\"\nBar\n(1 2 3)\n[4,5,6]\nabc::{def:42}", sb.toString());
}
use of com.amazon.ion.system.IonTextWriterBuilder 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.system.IonTextWriterBuilder in project ion-java by amzn.
the class RoundTripStreamingTest method makeText.
/**
* Use IonReader to consume the buffer, and IonTextWriter to print it out.
*/
private byte[] makeText(byte[] buffer, boolean prettyPrint) throws IOException {
IonReader in = makeIterator(buffer);
ByteArrayOutputStream out = new ByteArrayOutputStream();
IonTextWriterBuilder b = IonTextWriterBuilder.standard();
if (prettyPrint) {
b.withPrettyPrinting();
}
b.setInitialIvmHandling(SUPPRESS);
IonWriter tw = b.build(out);
tw.writeValues(in);
tw.close();
in.close();
// this is utf-8
byte[] buf = out.toByteArray();
return buf;
}
Aggregations