use of com.amazon.ion.IonWriter in project ion-java by amzn.
the class Printer method print.
// =========================================================================
// Print methods
public void print(IonValue value, Appendable out) throws IOException {
// Copy the options so visitor won't see changes made while printing.
Options options;
synchronized (// So we don't clone in the midst of changes
this) {
options = myOptions.clone();
}
if (true) {
_print(value, makeVisitor(options, out));
} else {
// Bridge to the configurable text writer. This is here for
// testing purposes. It *almost* works except for printing
// datagram as list.
boolean dg = value instanceof IonDatagram;
_Private_IonTextWriterBuilder o = _Private_IonTextWriterBuilder.standard();
o.setCharset(IonTextWriterBuilder.ASCII);
if (dg) {
if (options.skipSystemValues) {
o.withMinimalSystemData();
} else if (options.simplifySystemValues) {
o.setIvmMinimizing(IvmMinimizing.DISTANT);
o.setLstMinimizing(LstMinimizing.LOCALS);
}
}
o._blob_as_string = options.blobAsString;
o._clob_as_string = options.clobAsString;
o._decimal_as_float = options.decimalAsFloat;
// TODO datagram as list
o._sexp_as_list = options.sexpAsList;
o._skip_annotations = options.skipAnnotations;
o._string_as_json = options.stringAsJson;
o._symbol_as_string = options.symbolAsString;
o._timestamp_as_millis = options.timestampAsMillis;
o._timestamp_as_string = options.timestampAsString;
o._untyped_nulls = options.untypedNulls;
IonWriter writer = o.build(out);
// TODO doesn't work for datagram since it skips system values
// value.writeTo(writer);
_Private_IonSystem system = (_Private_IonSystem) value.getSystem();
IonReader reader = system.newSystemReader(value);
writer.writeValues(reader);
writer.finish();
}
}
use of com.amazon.ion.IonWriter in project ion-java by amzn.
the class _Private_IonWriterFactory method makeSystemWriter.
/**
* @param container must not be null.
*/
public static IonWriter makeSystemWriter(IonContainer container) {
IonSystem sys = container.getSystem();
IonCatalog cat = sys.getCatalog();
SymbolTable defaultSystemSymtab = sys.getSystemSymbolTable();
IonWriter writer = new IonWriterSystemTree(defaultSystemSymtab, cat, container, null);
return writer;
}
use of com.amazon.ion.IonWriter in project ion-java by amzn.
the class IonLoaderLite method load_helper.
/**
* This doesn't wrap IOException because some callers need to propagate it.
*
* @return a new datagram; not null.
*/
private IonDatagramLite load_helper(IonReader reader) throws IOException {
IonDatagramLite datagram = new IonDatagramLite(_system, _catalog);
IonWriter writer = _Private_IonWriterFactory.makeWriter(datagram);
writer.writeValues(reader);
return datagram;
}
use of com.amazon.ion.IonWriter in project ion-java by amzn.
the class IonTextWriterBuilderTest method testInitialIvmSuppression.
@Test
public void testInitialIvmSuppression() throws IOException {
IonTextWriterBuilder b = IonTextWriterBuilder.standard();
StringBuilder out = new StringBuilder();
IonWriter writer = b.build(out);
writer.writeSymbol(ION_1_0);
writer.writeNull();
writer.writeSymbol(ION_1_0);
writer.close();
assertEquals(ION_1_0 + " null " + ION_1_0, out.toString());
b.withInitialIvmHandling(SUPPRESS);
out.setLength(0);
writer = b.build(out);
writer.writeSymbol(ION_1_0);
writer.writeSymbol(ION_1_0);
writer.writeNull();
writer.writeSymbol(ION_1_0);
writer.close();
assertEquals("null " + ION_1_0, out.toString());
}
use of com.amazon.ion.IonWriter in project ion-java by amzn.
the class IonTextWriterBuilderTest method testImports.
// -------------------------------------------------------------------------
@Test
public void testImports() {
SymbolTable f = Symtabs.CATALOG.getTable("fred", 1);
SymbolTable g = Symtabs.CATALOG.getTable("ginger", 1);
SymbolTable[] symtabsF = new SymbolTable[] { f };
SymbolTable[] symtabsG = new SymbolTable[] { g };
IonTextWriterBuilder b = IonTextWriterBuilder.standard();
b.setImports(f);
StringBuilder out = new StringBuilder();
IonWriter writer = b.build(out);
SymbolTable st = writer.getSymbolTable();
assertArrayEquals(symtabsF, st.getImportedTables());
// Test with...() on mutable builder
IonTextWriterBuilder b2 = b.withImports(g);
assertSame(b, b2);
assertArrayEquals(symtabsG, b2.getImports());
// Test with...() on immutable builder
b2 = b.immutable();
assertArrayEquals(symtabsG, b2.getImports());
IonTextWriterBuilder b3 = b2.withImports(f);
assertNotSame(b2, b3);
assertArrayEquals(symtabsG, b2.getImports());
assertArrayEquals(symtabsF, b3.getImports());
// Test cloning of array
SymbolTable[] symtabs = new SymbolTable[] { f };
b3.setImports(symtabs);
assertNotSame(symtabs, b3.getImports());
assertArrayEquals(symtabsF, b3.getImports());
symtabs[0] = g;
assertArrayEquals(symtabsF, b3.getImports());
b3.getImports()[0] = g;
assertArrayEquals(symtabsF, b3.getImports());
}
Aggregations