use of com.amazon.ion.IonWriter in project ion-java by amzn.
the class IonMarkupWriterTest method testPrettyCallback.
@Test
public void testPrettyCallback() throws IOException {
// Write to a StringWriter for testing
StringWriter out = new StringWriter();
IonReader ionReader = system().newReader(input);
_Private_IonTextWriterBuilder builder = (_Private_IonTextWriterBuilder) IonTextWriterBuilder.pretty();
IonWriter ionWriter = builder.withCallbackBuilder(new TestMarkupCallback.Builder()).build(out);
write(ionReader, ionWriter);
assertEquals("Markup callback with pretty printing Ion Writer," + " error with data:\n" + input + "\n", pExpected, out.toString());
}
use of com.amazon.ion.IonWriter in project ion-java by amzn.
the class IonMarkupWriterTest method testEscaping.
@Test
public void testEscaping() throws IOException {
String input = "These should be escaped <>&";
String expected = "<><><>&&&<><><>\"These should be escaped <>&\"";
StringWriter out = new StringWriter();
_Private_IonTextWriterBuilder builder = (_Private_IonTextWriterBuilder) IonTextWriterBuilder.standard();
IonWriter ionWriter = builder.withCallbackBuilder(new EscapingCallback.Builder()).build(out);
ionWriter.writeString(input);
ionWriter.finish();
assertEquals("Escaping failed, with data:\n" + input + "\n", expected, out.toString());
}
use of com.amazon.ion.IonWriter in project ion-java by amzn.
the class IonMarkupWriterTest method testStandardCallback.
@Test
public void testStandardCallback() throws IOException {
// Write to a StringWriter for testing
StringWriter out = new StringWriter();
IonReader ionReader = system().newReader(input);
_Private_IonTextWriterBuilder builder = (_Private_IonTextWriterBuilder) IonTextWriterBuilder.standard();
IonWriter ionWriter = builder.withCallbackBuilder(new TestMarkupCallback.Builder()).build(out);
write(ionReader, ionWriter);
assertEquals("Markup callback with standard Ion Writer, " + "error with data:\n" + input + "\n", sExpected, out.toString());
}
use of com.amazon.ion.IonWriter in project ion-java by amzn.
the class IonSystemLite method clone.
@SuppressWarnings("unchecked")
public <T extends IonValue> T clone(T value) throws IonException {
// Use "fast clone" when the system is the same.
if (value.getSystem() == this) {
return (T) value.clone();
}
if (value instanceof IonDatagram) {
IonDatagram datagram = newDatagram();
IonWriter writer = _Private_IonWriterFactory.makeWriter(datagram);
IonReader reader = makeSystemReader(value.getSystem(), value);
try {
writer.writeValues(reader);
} catch (IOException e) {
throw new IonException(e);
}
return (T) datagram;
}
IonReader reader = newReader(value);
reader.next();
return (T) newValue(reader);
}
use of com.amazon.ion.IonWriter in project ion-java by amzn.
the class IonValueLite method toString.
public String toString(IonTextWriterBuilder writerBuilder) {
StringBuilder buf = new StringBuilder(1024);
try {
IonWriter writer = writerBuilder.build(buf);
writeTo(writer);
writer.finish();
} catch (IOException e) {
throw new IonException(e);
}
return buf.toString();
}
Aggregations