use of com.amazon.ion.IonWriter in project ion-java by amzn.
the class IonBinaryWriterBuilderTest 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 };
IonBinaryWriterBuilder b = IonBinaryWriterBuilder.standard();
b.setImports(f);
OutputStream out = new ByteArrayOutputStream();
IonWriter writer = b.build(out);
SymbolTable st = writer.getSymbolTable();
assertArrayEquals(symtabsF, st.getImportedTables());
// Test with...() on mutable builder
IonBinaryWriterBuilder b2 = b.withImports(g);
assertSame(b, b2);
assertArrayEquals(symtabsG, b2.getImports());
// Test with...() on immutable builder
b2 = b.immutable();
assertArrayEquals(symtabsG, b2.getImports());
IonBinaryWriterBuilder 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());
}
use of com.amazon.ion.IonWriter in project ion-java by amzn.
the class IonReaderBuilderTest method testSystemFreeRoundtrip.
@Test
public void testSystemFreeRoundtrip() throws IOException {
// No IonSystem in sight.
ByteArrayOutputStream out = new ByteArrayOutputStream();
IonWriter writer = _Private_IonBinaryWriterBuilder.standard().build(out);
writer.writeInt(42);
writer.finish();
IonReader reader = IonReaderBuilder.standard().build(out.toByteArray());
assertEquals(IonType.INT, reader.next());
assertEquals(42, reader.intValue());
}
use of com.amazon.ion.IonWriter in project ion-java by amzn.
the class IonSystemBuilderTest method testStreamCopyOptimized.
// -------------------------------------------------------------------------
@Test
public void testStreamCopyOptimized() {
IonSystemBuilder b = IonSystemBuilder.standard().copy();
b.setStreamCopyOptimized(true);
IonSystem ion = b.build();
assertTrue(isLiteSystem(ion));
ByteArrayOutputStream out = new ByteArrayOutputStream();
IonWriter w = ion.newBinaryWriter(out);
assertTrue(((_Private_IonWriter) w).isStreamCopyOptimized());
}
use of com.amazon.ion.IonWriter in project ion-java by amzn.
the class IonTextWriterBuilderTest method testCustomCatalog.
// -------------------------------------------------------------------------
@Test
public void testCustomCatalog() {
IonCatalog catalog = new SimpleCatalog();
IonTextWriterBuilder b = IonTextWriterBuilder.standard();
b.setCatalog(catalog);
assertSame(catalog, b.getCatalog());
StringBuilder out = new StringBuilder();
IonWriter writer = b.build(out);
assertSame(catalog, ((_Private_IonWriter) writer).getCatalog());
IonCatalog catalog2 = new SimpleCatalog();
b.setCatalog(catalog2);
assertSame(catalog2, b.getCatalog());
// Test with...() on mutable builder
IonTextWriterBuilder b2 = b.withCatalog(catalog);
assertSame(b, b2);
assertSame(catalog, b2.getCatalog());
// Test with...() on immutable builder
b2 = b.immutable();
assertSame(catalog, b2.getCatalog());
IonTextWriterBuilder b3 = b2.withCatalog(catalog2);
assertNotSame(b2, b3);
assertSame(catalog, b2.getCatalog());
assertSame(catalog2, b3.getCatalog());
}
use of com.amazon.ion.IonWriter in project ion-java by amzn.
the class IonTextWriterBuilderTest method testStandard.
@Test
public void testStandard() {
IonTextWriterBuilder b = IonTextWriterBuilder.standard();
Assert.assertNotNull(b);
testBuildNull(b);
StringBuilder out = new StringBuilder();
IonWriter writer = b.build(out);
Assert.assertNotNull(writer);
assertNotSame(b, IonTextWriterBuilder.standard());
}
Aggregations