use of com.amazon.ion.IonBinaryWriter in project ion-java by amzn.
the class BinaryStreamingTest method testValue1.
@Test
public void testValue1() 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,}";
IonReader ir = system().newReader(s);
IonBinaryWriter wr = system().newBinaryWriter();
wr.writeValues(ir);
byte[] buffer = wr.getBytes();
dumpBuffer(buffer, buffer.length);
}
use of com.amazon.ion.IonBinaryWriter in project ion-java by amzn.
the class BinaryStreamingTest method testBenchmarkDirect.
@Test
public void testBenchmarkDirect() throws IOException {
byte[] bytes;
IonBinaryWriter wr = system().newBinaryWriter();
wr.stepIn(IonType.STRUCT);
wr.setFieldName("12");
wr.addTypeAnnotation(int.class.getCanonicalName());
wr.writeInt(-12);
wr.setFieldName("12242.124598129");
wr.addTypeAnnotation(double.class.getCanonicalName());
wr.writeFloat(12242.124598129);
wr.setFieldName("Almost Done.");
wr.addTypeAnnotation(boolean.class.getCanonicalName());
wr.writeBool(true);
wr.setFieldName("This is a test String.");
wr.addTypeAnnotation(boolean.class.getCanonicalName());
wr.writeBool(true);
wr.setFieldName("false");
wr.addTypeAnnotation(boolean.class.getCanonicalName());
wr.writeBool(false);
wr.setFieldName("long");
wr.addTypeAnnotation(long.class.getCanonicalName());
wr.writeInt((long) 9326);
wr.setFieldName("true");
wr.addTypeAnnotation(boolean.class.getCanonicalName());
wr.writeBool(true);
wr.stepOut();
bytes = wr.getBytes();
IonReader ir = getStreamingMode().newIonReader(system().getCatalog(), bytes);
assertEquals(IonType.STRUCT, ir.next());
ir.stepIn();
if (!_Private_Utils.READER_HASNEXT_REMOVED)
assertTrue(ir.hasNext());
assertEquals(ir.next(), IonType.INT);
expectField(ir, "12");
assertEquals(ir.intValue(), -12);
if (!_Private_Utils.READER_HASNEXT_REMOVED)
assertTrue(ir.hasNext());
assertEquals(ir.next(), IonType.FLOAT);
expectField(ir, "12242.124598129");
assertEquals(ir.doubleValue(), 12242.124598129);
if (!_Private_Utils.READER_HASNEXT_REMOVED)
assertTrue(ir.hasNext());
assertEquals(ir.next(), IonType.BOOL);
expectField(ir, "Almost Done.");
assertEquals(ir.booleanValue(), true);
if (!_Private_Utils.READER_HASNEXT_REMOVED)
assertTrue(ir.hasNext());
assertEquals(ir.next(), IonType.BOOL);
expectField(ir, "This is a test String.");
assertEquals(ir.booleanValue(), true);
if (!_Private_Utils.READER_HASNEXT_REMOVED)
assertTrue(ir.hasNext());
assertEquals(ir.next(), IonType.BOOL);
expectField(ir, "false");
assertEquals(ir.booleanValue(), false);
if (!_Private_Utils.READER_HASNEXT_REMOVED)
assertTrue(ir.hasNext());
assertEquals(ir.next(), IonType.INT);
expectField(ir, "long");
assertEquals(ir.longValue(), 9326L);
if (!_Private_Utils.READER_HASNEXT_REMOVED)
assertTrue(ir.hasNext());
assertEquals(ir.next(), IonType.BOOL);
expectField(ir, "true");
assertEquals(ir.booleanValue(), true);
if (!_Private_Utils.READER_HASNEXT_REMOVED)
assertFalse(ir.hasNext());
assertEquals(null, ir.next());
ir.stepOut();
if (!_Private_Utils.READER_HASNEXT_REMOVED)
assertFalse(ir.hasNext());
assertEquals(null, ir.next());
ir.close();
}
use of com.amazon.ion.IonBinaryWriter in project ion-java by amzn.
the class BinaryStreamingTest 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);
IonValue v2 = ((IonStruct) v).get("offline_store_only");
SymbolTable sym = v.getSymbolTable();
assert v2.getSymbolTable() == sym;
IonReader ir = system().newReader(s);
Iterator<String> symbols = sym.iterateDeclaredSymbolNames();
SymbolTable u = system().newSharedSymbolTable("items", 1, symbols);
IonBinaryWriter wr = system().newBinaryWriter(u);
wr.writeValues(ir);
byte[] buffer = wr.getBytes();
dumpBuffer(buffer, buffer.length);
ir = getStreamingMode().newIonReader(system().getCatalog(), buffer);
wr = system().newBinaryWriter(u);
wr.writeValues(ir);
buffer = wr.getBytes();
dumpBuffer(buffer, buffer.length);
}
use of com.amazon.ion.IonBinaryWriter in project ion-java by amzn.
the class BinaryStreamingTest method testBoolValue.
@Test
public void testBoolValue() throws Exception {
IonBinaryWriter wr = system().newBinaryWriter();
byte[] buffer = null;
try {
wr.stepIn(IonType.STRUCT);
wr.setFieldName("Foo");
wr.writeBool(true);
wr.stepOut();
buffer = wr.getBytes();
} catch (IOException e) {
throw new Exception(e);
}
IonReader ir = getStreamingMode().newIonReader(system().getCatalog(), buffer);
IonType t = ir.next();
if (t != null) {
ir.stepIn();
t = ir.next();
while (t != null) {
String name = ir.getFieldName();
boolean value = ir.booleanValue();
assertTrue(value);
if (BinaryStreamingTest._debug_flag) {
System.out.println(t + " " + name + ": " + value);
}
t = ir.next();
}
}
ir.close();
}
use of com.amazon.ion.IonBinaryWriter in project ion-java by amzn.
the class TextWriterTest method testLstMinimizing.
@Test
public void testLstMinimizing() throws Exception {
SymbolTable fred1 = Symtabs.register("fred", 1, catalog());
IonBinaryWriter binaryWriter = system().newBinaryWriter(fred1);
binaryWriter.writeSymbol("fred_1");
binaryWriter.writeSymbol("ginger");
binaryWriter.finish();
byte[] binaryData = binaryWriter.getBytes();
options = IonTextWriterBuilder.standard();
// TODO User reader still transfers local symtabs!
IonReader binaryReader = system().newReader(binaryData);
iw = makeWriter();
iw.writeValues(binaryReader);
String ionText = outputString();
assertEquals("$ion_symbol_table::{imports:[{name:\"fred\",version:1,max_id:2}]," + "symbols:[\"ginger\"]} " + "fred_1 ginger", ionText);
options.setLstMinimizing(LstMinimizing.LOCALS);
binaryReader = system().newReader(binaryData);
iw = makeWriter();
iw.writeValues(binaryReader);
ionText = outputString();
assertEquals("$ion_symbol_table::{imports:[{name:\"fred\",version:1,max_id:2}]} " + "fred_1 ginger", ionText);
options.setLstMinimizing(LstMinimizing.EVERYTHING);
binaryReader = system().newReader(binaryData);
iw = makeWriter();
iw.writeValues(binaryReader);
ionText = outputString();
assertEquals("$ion_1_0 fred_1 ginger", ionText);
options.setInitialIvmHandling(SUPPRESS);
binaryReader = system().newReader(binaryData);
iw = makeWriter();
iw.writeValues(binaryReader);
ionText = outputString();
assertEquals("fred_1 ginger", ionText);
}
Aggregations