use of com.amazon.ion.IonSystem in project ion-java by amzn.
the class MiscStreamingTest method testValue2.
@Test
public void testValue2() throws Exception {
String s = "item_view::{item_id:\"B00096H8Q4\",marketplace_id:2," + "product:{item_name:[" + "{value:'''Method 24CT Leather Wipes''',lang:EN_CA}," + "{value:'''Method 24CT Chiffons de Cuir''',lang:FR_CA}]," + "list_price:{value:18.23,unit:EUR},}" + ",index_suppressed:true," + "offline_store_only:true,version:2,}";
IonSystem sys = system();
IonDatagram dg = sys.getLoader().load(s);
IonValue v = dg.get(0);
IonType t = v.getType();
assertSame("should be a struct", IonType.STRUCT, t);
int tree_count = ((IonStruct) v).size();
IonReader it = system().newReader(s);
t = it.next();
assertSame("should be a struct", IonType.STRUCT, t);
int string_count = 0;
it.stepIn();
while (it.next() != null) {
string_count++;
}
it.stepOut();
assertSame("tree and string iterator should have the same size", tree_count, string_count);
byte[] buf = dg.getBytes();
it = system().newReader(buf);
t = it.next();
assertSame("should be a struct", IonType.STRUCT, t);
int bin_count = 0;
it.stepIn();
while (it.next() != null) {
bin_count++;
}
it.stepOut();
assertSame("tree and binary iterator should have the same size", tree_count, bin_count);
}
use of com.amazon.ion.IonSystem 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.IonSystem in project ion-java by amzn.
the class IonBinaryWriterBuilderTest method testSymtabValueFactory.
// -------------------------------------------------------------------------
@Test
public void testSymtabValueFactory() {
IonSystem system = IonSystemBuilder.standard().build();
_Private_IonBinaryWriterBuilder b = _Private_IonBinaryWriterBuilder.standard();
b.setSymtabValueFactory(system);
assertSame(system, b.getSymtabValueFactory());
// The value factory isn't visible through other APIs so we can't
// really test any further.
}
use of com.amazon.ion.IonSystem 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.IonSystem 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