use of com.amazon.ion.IonSystem in project ion-java by amzn.
the class PrintApp method process.
protected void process(IonReader reader, OutputStream out) throws IOException, IonException {
IonSystem system = this.mySystem;
IonWriter writer = system.newTextWriter(out);
writer.writeValues(reader);
// Ensure there's a newline at the end and flush the buffer.
out.write('\n');
out.flush();
}
use of com.amazon.ion.IonSystem in project ion-java by amzn.
the class SymbolTableTest method testMutateDomAfterLocalSymbolTableAppend.
@Test
public void testMutateDomAfterLocalSymbolTableAppend() throws IOException {
String text = LocalSymbolTablePrefix + "{" + " imports:[{name:\"foo\", version:1, max_id:1}], " + " symbols:[\"s1\", \"s2\"]" + "}\n" + // Symbol with unknown text from "foo"
"$10\n" + // s1
"$11\n" + LocalSymbolTablePrefix + "{" + " imports:" + ION_SYMBOL_TABLE + "," + " symbols:[\"s3\"]" + "}\n" + // s2
"$12";
IonDatagram datagram = loader().load(text);
datagram.add(1, system().newSymbol("abc"));
// s3
datagram.add(system().newSymbol(new SymbolTokenImpl(null, 13)));
// Symbol with unknown text from "foo"
datagram.add(system().newSymbol(new SymbolTokenImpl(null, 10)));
ByteArrayOutputStream textOutput = new ByteArrayOutputStream();
ByteArrayOutputStream binaryOutput = new ByteArrayOutputStream();
List<String> fooSymbols = Collections.singletonList("bar");
SymbolTable fooTable = system().newSharedSymbolTable("foo", 1, fooSymbols.iterator());
IonWriter textWriter = IonTextWriterBuilder.standard().withImports(fooTable).build(textOutput);
datagram.writeTo(textWriter);
textWriter.close();
IonWriter binaryWriter = IonBinaryWriterBuilder.standard().withImports(fooTable).build(binaryOutput);
datagram.writeTo(binaryWriter);
binaryWriter.close();
SimpleCatalog catalog = new SimpleCatalog();
catalog.putTable(fooTable);
IonSystem system = IonSystemBuilder.standard().withCatalog(catalog).build();
IonDatagram textRoundtrip = system.getLoader().load(textOutput.toByteArray());
IonDatagram binaryRoundtrip = system.getLoader().load(binaryOutput.toByteArray());
assertEquals(textRoundtrip, binaryRoundtrip);
assertEquals("bar", ((IonSymbol) textRoundtrip.get(0)).stringValue());
assertEquals("abc", ((IonSymbol) textRoundtrip.get(1)).stringValue());
assertEquals("s1", ((IonSymbol) textRoundtrip.get(2)).stringValue());
assertEquals("s2", ((IonSymbol) textRoundtrip.get(3)).stringValue());
assertEquals("s3", ((IonSymbol) textRoundtrip.get(4)).stringValue());
assertEquals("bar", ((IonSymbol) textRoundtrip.get(0)).stringValue());
}
use of com.amazon.ion.IonSystem 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.IonSystem 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.IonSystem in project ion-java by amzn.
the class SymbolTableTest method registerImportedV2.
public SymbolTable registerImportedV2() {
IonSystem system = system();
String importingText = SharedSymbolTablePrefix + "{" + " name:'''imported''', version:2," + " symbols:[" + " '''imported 1'''," + " '''imported 2'''," + " '''fred3'''," + " '''fred4'''," + " ]" + "}";
SymbolTable shared = registerSharedSymtab(importingText);
assertEquals(IMPORTED_2_MAX_ID, shared.getMaxId());
SymbolTable importedTable = system.getCatalog().getTable("imported", 2);
assertSame(shared, importedTable);
return importedTable;
}
Aggregations