in ion-java-cli/src/com/amazon/tools/events/Event.java [47:150]
public int writeOutput(IonWriter ionWriterForOutput,
int eventIndex) throws IOException {
ionWriterForOutput.stepIn(IonType.STRUCT);
if (this.eventType != null) {
ionWriterForOutput.setFieldName("event_type");
ionWriterForOutput.writeSymbol(this.eventType.toString());
}
if (this.ionType != null) {
ionWriterForOutput.setFieldName("ion_type");
ionWriterForOutput.writeSymbol(this.ionType.toString());
}
if (this.fieldName != null) {
ionWriterForOutput.setFieldName("field_name");
ionWriterForOutput.stepIn(IonType.STRUCT);
ionWriterForOutput.setFieldName("text");
if (this.fieldName.getText() == null) {
ionWriterForOutput.writeNull();
} else {
ionWriterForOutput.writeString(this.fieldName.getText());
}
ionWriterForOutput.setFieldName("import_location");
ionWriterForOutput.writeNull();
ionWriterForOutput.stepOut();
}
if (this.annotations != null && this.annotations.length > 0) {
ionWriterForOutput.setFieldName("annotations");
ionWriterForOutput.stepIn(IonType.LIST);
for (SymbolToken annotation : this.annotations) {
ionWriterForOutput.stepIn(IonType.STRUCT);
ionWriterForOutput.setFieldName("text");
String text = annotation.getText();
if (text == null) {
ionWriterForOutput.writeNull();
ionWriterForOutput.setFieldName("import_location");
ionWriterForOutput.writeNull();
} else {
ionWriterForOutput.writeString(text);
}
ionWriterForOutput.stepOut();
}
ionWriterForOutput.stepOut();
}
if (this.value != null) {
String valueText;
byte[] valueBinary;
try (
ByteArrayOutputStream textOut = new ByteArrayOutputStream();
IonWriter textWriter = IonTextWriterBuilder.standard().build(textOut);
ByteArrayOutputStream binaryOut = new ByteArrayOutputStream();
IonWriter binaryWriter = IonBinaryWriterBuilder.standard().build(binaryOut);
) {
//write Text
this.value.writeTo(textWriter);
textWriter.finish();
valueText = textOut.toString("utf-8");
ionWriterForOutput.setFieldName("value_text");
ionWriterForOutput.writeString(valueText);
//write binary
this.value.writeTo(binaryWriter);
binaryWriter.finish();
valueBinary = binaryOut.toByteArray();
ionWriterForOutput.setFieldName("value_binary");
ionWriterForOutput.stepIn(IonType.LIST);
for (byte b : valueBinary) {
ionWriterForOutput.writeInt(b & 0xff);
}
ionWriterForOutput.stepOut();
}
}
if (this.imports != null && this.imports.length > 0) {
ionWriterForOutput.setFieldName("imports");
ionWriterForOutput.stepIn(IonType.LIST);
for (ImportDescriptor anImport : this.imports) {
ionWriterForOutput.stepIn(IonType.STRUCT);
ionWriterForOutput.setFieldName("name");
ionWriterForOutput.writeString(anImport.getImportName());
ionWriterForOutput.setFieldName("version");
ionWriterForOutput.writeInt(anImport.getVersion());
ionWriterForOutput.setFieldName("max_id");
ionWriterForOutput.writeInt(anImport.getMaxId());
ionWriterForOutput.stepOut();
}
ionWriterForOutput.stepOut();
}
if (this.depth != -1) {
ionWriterForOutput.setFieldName("depth");
ionWriterForOutput.writeInt(this.depth);
}
ionWriterForOutput.stepOut();
//event index + 1 if we write OutputStream successfully.
return eventIndex + 1;
}