use of com.amazon.ion.IonWriter in project ion-java by amzn.
the class MiscStreamingTest method testTextWriterSymtabs.
@Test
public void testTextWriterSymtabs() throws IOException {
ByteArrayOutputStream out = new ByteArrayOutputStream();
IonWriter writer = system().newTextWriter(out);
system().newSymbol("foo").writeTo(writer);
writer.close();
assertEquals("foo", utf8(out.toByteArray()));
}
use of com.amazon.ion.IonWriter in project ion-java by amzn.
the class IonBinaryWriterBuilderTest method testSetIsFloatBinary32Enabled.
// -------------------------------------------------------------------------
@Test
public void testSetIsFloatBinary32Enabled() throws IOException {
IonSystem system = IonSystemBuilder.standard().build();
IonBinaryWriterBuilder b = IonBinaryWriterBuilder.standard();
b.setIsFloatBinary32Enabled(true);
ByteArrayOutputStream out = new ByteArrayOutputStream();
IonWriter writer = b.build(out);
writer.writeFloat(1.0);
writer.close();
assertEquals(9, out.size());
assertEquals(system.newFloat(1.0), system.singleValue(out.toByteArray()));
b.setIsFloatBinary32Enabled(false);
out = new ByteArrayOutputStream();
writer = b.build(out);
writer.writeFloat(1.0);
writer.close();
assertEquals(13, out.size());
assertEquals(system.newFloat(1.0), system.singleValue(out.toByteArray()));
}
use of com.amazon.ion.IonWriter in project ion-java by amzn.
the class IonBinaryWriterBuilderTest method testWithFloatBinary32Enabled.
@Test
public void testWithFloatBinary32Enabled() throws IOException {
IonSystem system = IonSystemBuilder.standard().build();
IonBinaryWriterBuilder b = IonBinaryWriterBuilder.standard().withFloatBinary32Enabled();
ByteArrayOutputStream out = new ByteArrayOutputStream();
IonWriter writer = b.build(out);
writer.writeFloat(1.0);
writer.close();
assertEquals(9, out.size());
assertEquals(system.newFloat(1.0), system.singleValue(out.toByteArray()));
}
use of com.amazon.ion.IonWriter in project ion-java by amzn.
the class IonBinaryWriterBuilderTest method testInitialSymtab.
// -------------------------------------------------------------------------
@Test
public void testInitialSymtab() throws IOException {
SymbolTable sst = _Private_Utils.systemSymtab(1);
SymbolTable lst0 = Symtabs.localSymbolTableFactory().newLocalSymtab(sst);
lst0.intern("hello");
_Private_IonBinaryWriterBuilder b = _Private_IonBinaryWriterBuilder.standard();
b.setInitialSymbolTable(lst0);
assertSame(lst0, b.getInitialSymbolTable());
OutputStream out = new ByteArrayOutputStream();
IonWriter writer = b.build(out);
assertEquals(sst.getMaxId() + 1, writer.getSymbolTable().findSymbol("hello"));
// Builder makes a copy of the symtab
SymbolTable lst1 = writer.getSymbolTable();
assertNotSame(lst0, lst1);
assertSame(lst0, b.getInitialSymbolTable());
// Second call to build, we get another copy.
writer = b.build(out);
SymbolTable lst2 = writer.getSymbolTable();
assertNotSame(lst0, lst2);
assertNotSame(lst1, lst2);
writer.writeSymbol("addition");
// Now the LST has been extended, so the builder should make a copy
// with the original max_id.
writer = b.build(out);
SymbolTable lst3 = writer.getSymbolTable();
assertEquals(sst.getMaxId() + 1, lst3.findSymbol("hello"));
assertEquals(sst.getMaxId() + 1, lst3.getMaxId());
assertNotSame(lst0, lst3);
assertNotSame(lst1, lst3);
assertNotSame(lst2, lst3);
assertSame(lst0, b.getInitialSymbolTable());
}
use of com.amazon.ion.IonWriter in project ion-java by amzn.
the class IonBinaryWriterBuilderTest method testWithFloatBinary32Disabled.
@Test
public void testWithFloatBinary32Disabled() throws IOException {
IonSystem system = IonSystemBuilder.standard().build();
IonBinaryWriterBuilder b = IonBinaryWriterBuilder.standard().withFloatBinary32Disabled();
ByteArrayOutputStream out = new ByteArrayOutputStream();
IonWriter writer = b.build(out);
writer.writeFloat(1.0);
writer.close();
assertEquals(13, out.size());
assertEquals(system.newFloat(1.0), system.singleValue(out.toByteArray()));
}
Aggregations