use of com.amazon.ion.IonValue in project ion-java by amzn.
the class IonAssert method assertStructEquals.
private static void assertStructEquals(String path, IonStruct expected, IonStruct actual) {
int expectedSize = expected.size();
int actualSize = actual.size();
if (expectedSize != actualSize) {
fail(String.format("%s size, expected:%s actual:%s", path, expectedSize, actualSize));
}
Map<SymbolToken, List<IonValue>> expectedFields = sortFields(expected);
Map<SymbolToken, List<IonValue>> actualFields = sortFields(actual);
for (Entry<SymbolToken, List<IonValue>> expectedEntry : expectedFields.entrySet()) {
SymbolToken token = expectedEntry.getKey();
String fieldPath = path + '.' + printSymbol(token);
List<IonValue> actualList = actualFields.get(token);
if (actualList == null) {
fail(String.format("Missing field %s, expected: %s actual: %s", fieldPath, expected, actual));
}
assertFieldEquals(fieldPath, expectedEntry.getValue(), actual, actualList);
}
}
use of com.amazon.ion.IonValue in project ion-java by amzn.
the class IteratorTiming method main.
public static void main(String[] args) {
IonSystem ion = IonSystemBuilder.standard().build();
System.out.println("Start at " + new Date());
try {
InputStream is = new FileInputStream(args[0]);
Iterator<IonValue> itera = ion.iterate(new InputStreamReader(is));
int count = 0;
long start = System.currentTimeMillis();
long millis = start;
while (itera.hasNext()) {
itera.next();
if ((++count % 100) == 0) {
long diff = System.currentTimeMillis() - millis;
System.out.println(diff);
millis = System.currentTimeMillis();
}
}
long now = System.currentTimeMillis();
long elapsed = now - start;
System.out.println();
System.out.println("End at " + new Date());
System.out.println("Total millis: " + elapsed);
System.out.println("# values: " + count);
System.out.println("avg millis/value: " + ((float) elapsed) / count);
Runtime rt = Runtime.getRuntime();
System.out.println("Total memory: " + rt.totalMemory());
} catch (IOException e) {
System.err.println(e);
}
}
use of com.amazon.ion.IonValue 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.IonValue in project ion-java by amzn.
the class SymbolTableTest method testOverridingSystemSymbolId.
/**
* Attempts to override system symbols are ignored.
*/
@Test
public void testOverridingSystemSymbolId() {
String importingText = LocalSymbolTablePrefix + "{" + " symbols:[ '''" + NAME + "''' ]," + "}\n" + "null";
Iterator<IonValue> scanner = system().iterate(importingText);
IonValue v = scanner.next();
SymbolTable symtab = v.getSymbolTable();
assertTrue(symtab.isLocalTable());
checkSymbol(NAME, NAME_SID, symtab);
}
use of com.amazon.ion.IonValue in project ion-java by amzn.
the class SymbolTableTest method testImportsFollowSymbols.
@Test
public void testImportsFollowSymbols() {
registerImportedV1();
final int import1id = systemMaxId() + 1;
final int local1id = systemMaxId() + IMPORTED_1_MAX_ID + 1;
final int local2id = local1id + 1;
String importingText = "$ion_1_0 " + LocalSymbolTablePrefix + "{" + " symbols:[ '''local1''' ]," + " imports:[{name:'''imported''', version:1, max_id:2}]," + "}\n" + // This symbol is added to end of locals
"local2\n" + "local1\n" + "'imported 1'";
Iterator<IonValue> scanner = system().iterate(importingText);
IonValue value = scanner.next();
SymbolTable symtab = value.getSymbolTable();
checkLocalTable(symtab);
checkSymbol("local2", value);
value = scanner.next();
checkSymbol("local1", local1id, value);
value = scanner.next();
checkSymbol("imported 1", import1id, value);
}
Aggregations