use of com.amazon.ion.IonSystem in project ion-java by amzn.
the class IonSystemBuilderTest method testStandard.
@Test
public void testStandard() {
assertEquals(null, IonSystemBuilder.standard().getCatalog());
IonSystem ion = IonSystemBuilder.standard().build();
assertTrue(isLiteSystem(ion));
assertSame(SimpleCatalog.class, ion.getCatalog().getClass());
}
use of com.amazon.ion.IonSystem in project ion-java by amzn.
the class SimpleCatalogTest method testBenchmark.
@SuppressWarnings("unchecked")
@Test
public void testBenchmark() {
Map m = new HashMap();
String s = "hello";
m.put("This is a test String.", true);
m.put(s, true);
m.put("true", true);
m.put("false", false);
m.put("Something", null);
m.put("12242.124598129", 12242.124598129);
m.put("long", (long) 9326);
m.put("12", 12);
m.put("Almost Done.", true);
m.put("Date", new Date(-10000));
HashMap<String, String> hmap = new HashMap();
for (int i = 0; i < 10; i++) {
hmap.put("Key " + i, "value " + i);
}
TreeMap<String, String> tmap = new TreeMap();
for (int i = 0; i < 10; i++) {
tmap.put("Key " + i, "value " + i);
}
m.put("hmap", hmap);
m.put("tmap", tmap);
IonSystem sys = system();
IonStruct i_tmap, i_hmap, i_map;
Set<Entry<String, String>> set;
i_tmap = sys.newEmptyStruct();
set = tmap.entrySet();
for (Entry<String, String> e : set) {
IonString is = sys.newString(e.getValue());
i_tmap.add(e.getKey(), is);
}
i_hmap = sys.newEmptyStruct();
set = hmap.entrySet();
for (Entry<String, String> e : set) {
IonString is = sys.newString(e.getValue());
i_hmap.add(e.getKey(), is);
}
i_map = sys.newEmptyStruct();
set = tmap.entrySet();
for (Entry<String, String> e : set) {
Object val = e.getValue();
IonValue ival;
if (val instanceof String) {
ival = sys.newString((String) val);
} else if (e.getKey().equals("tmap")) {
ival = i_tmap;
} else if (e.getKey().equals("hmap")) {
ival = i_hmap;
} else {
throw new RuntimeException("ACK! there's something in this map I don't understand!");
}
i_map.add(e.getKey(), ival);
}
IonDatagram dg = sys.newDatagram(i_map);
byte[] bytes = dg.getBytes();
IonValue v2 = sys.singleValue(bytes);
assertNotNull(v2);
}
use of com.amazon.ion.IonSystem in project ion-java by amzn.
the class MiscStreamingTest method testBinaryAnnotation.
@Test
public void testBinaryAnnotation() 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", t, IonType.STRUCT);
// first make sure the ion tree got it right
assertTrue(v.hasTypeAnnotation("item_view"));
String[] ann = v.getTypeAnnotations();
assertTrue(ann.length == 1 && ann[0].equals("item_view"));
// now take the string and get a text iterator and
// make sure it got the annotation right
IonReader it = system().newReader(s);
t = it.next();
assertSame("should be a struct", t, IonType.STRUCT);
ann = it.getTypeAnnotations();
assertTrue(ann.length == 1 && ann[0].equals("item_view"));
// finally get the byte array from the tree, make a
// binary iterator and check its annotation handling
byte[] buf = dg.getBytes();
it = system().newReader(buf);
t = it.next();
assertSame("should be a struct", t, IonType.STRUCT);
ann = it.getTypeAnnotations();
assertTrue(ann.length == 1 && ann[0].equals("item_view"));
}
use of com.amazon.ion.IonSystem in project jackson-dataformats-binary by FasterXML.
the class IonParserTest method testFloatType.
@Test
public void testFloatType() throws IOException {
final ObjectReadContext ctxt = ObjectReadContext.empty();
final byte[] data = "{ score:0.291e0 }".getBytes();
IonSystem ion = IonSystemBuilder.standard().build();
final IonValue ionFloat = ion.newFloat(Float.MAX_VALUE);
IonReader reader = ionFloat.getSystem().newReader(data, 0, data.length);
// Find the object
reader.next();
// Step into the object
reader.stepIn();
// Step next.
reader.next();
final IonParser floatParser = ionFactory.createParser(ctxt, reader);
Assert.assertEquals(JsonParser.NumberType.DOUBLE, floatParser.getNumberType());
}
use of com.amazon.ion.IonSystem in project jackson-dataformats-binary by FasterXML.
the class IonParserTest method testGetTypeId.
@Test
public void testGetTypeId() throws IOException {
String className = "com.example.Struct";
final byte[] data = ("'" + className + "'::{ foo: \"bar\" }").getBytes("UTF-8");
IonSystem ion = IonSystemBuilder.standard().build();
IonReader reader = ion.newReader(data, 0, data.length);
IonFactory factory = new IonFactory();
IonParser parser = factory.createParser(ObjectReadContext.empty(), reader);
// advance to find START_OBJECT
parser.nextToken();
Assert.assertEquals(className, parser.getTypeId());
}
Aggregations