use of com.amazon.ion.IonWriter in project ion-java by amzn.
the class IonTextWriterBuilderTest method testIvmMinimization.
@Test
public void testIvmMinimization() throws IOException {
IonTextWriterBuilder b = IonTextWriterBuilder.standard();
StringBuilder out = new StringBuilder();
IonWriter writer = b.build(out);
writer.writeSymbol(ION_1_0);
writer.writeSymbol(ION_1_0);
writer.close();
assertEquals(ION_1_0 + " " + ION_1_0, out.toString());
b.withIvmMinimizing(ADJACENT);
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.writeSymbol(ION_1_0);
writer.close();
assertEquals(ION_1_0 + " null " + ION_1_0, out.toString());
b.withIvmMinimizing(DISTANT);
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.writeSymbol(ION_1_0);
writer.close();
assertEquals(ION_1_0 + " null", out.toString());
}
use of com.amazon.ion.IonWriter in project ion-java by amzn.
the class IonBinaryWriterBuilderTest method testCustomCatalog.
// -------------------------------------------------------------------------
@Test
public void testCustomCatalog() {
IonCatalog catalog = new SimpleCatalog();
IonBinaryWriterBuilder b = IonBinaryWriterBuilder.standard();
b.setCatalog(catalog);
assertSame(catalog, b.getCatalog());
OutputStream out = new ByteArrayOutputStream();
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
IonBinaryWriterBuilder b2 = b.withCatalog(catalog);
assertSame(b, b2);
assertSame(catalog, b2.getCatalog());
// Test with...() on immutable builder
b2 = b.immutable();
assertSame(catalog, b2.getCatalog());
IonBinaryWriterBuilder 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 IonBinaryWriterBuilderTest method testImmutableInitialSymtab.
@Test
public void testImmutableInitialSymtab() {
SymbolTable sst = _Private_Utils.systemSymtab(1);
// Immutable local symtabs shouldn't get copied.
SymbolTable lst = Symtabs.localSymbolTableFactory().newLocalSymtab(sst);
lst.intern("hello");
lst.makeReadOnly();
_Private_IonBinaryWriterBuilder b = _Private_IonBinaryWriterBuilder.standard();
b.setInitialSymbolTable(lst);
assertSame(lst, b.getInitialSymbolTable());
OutputStream out = new ByteArrayOutputStream();
IonWriter writer = b.build(out);
assertTrue(symbolTableEquals(lst, writer.getSymbolTable()));
writer = b.build(out);
assertTrue(symbolTableEquals(lst, writer.getSymbolTable()));
}
use of com.amazon.ion.IonWriter in project ion-java by amzn.
the class IonBinaryWriterBuilderTest method testStandard.
@Test
public void testStandard() {
IonBinaryWriterBuilder b = IonBinaryWriterBuilder.standard();
Assert.assertNotNull(b);
testBuildNull(b);
OutputStream out = new ByteArrayOutputStream();
IonWriter writer = b.build(out);
Assert.assertNotNull(writer);
assertNotSame(b, IonBinaryWriterBuilder.standard());
}
use of com.amazon.ion.IonWriter in project ion-java by amzn.
the class IonBinaryWriterBuilderTest method testStreamCopyOptimized.
// -------------------------------------------------------------------------
@Test
public void testStreamCopyOptimized() {
IonBinaryWriterBuilder b = IonBinaryWriterBuilder.standard();
b.setStreamCopyOptimized(true);
assertTrue(b.isStreamCopyOptimized());
OutputStream out = new ByteArrayOutputStream();
IonWriter w = b.build(out);
assertTrue(((_Private_IonWriter) w).isStreamCopyOptimized());
}
Aggregations