use of com.amazon.ion.IonWriter in project ion-java by amzn.
the class SharedSymbolTableTest method roundTrip.
public void roundTrip(String serializedSymbolTable) throws IOException {
IonReader reader = system().newReader(serializedSymbolTable);
SymbolTable stFromReader = myMaker.newSharedSymtab(system(), reader);
assertTrue(stFromReader.isSharedTable());
StringBuilder buf = new StringBuilder();
IonWriter out = system().newTextWriter(buf);
stFromReader.writeTo(out);
reader = system().newReader(buf.toString());
SymbolTable reloaded = myMaker.newSharedSymtab(system(), reader);
Symtabs.assertEqualSymtabs(stFromReader, reloaded);
}
use of com.amazon.ion.IonWriter in project ion-java by amzn.
the class IonManagedBinaryWriterTestCase method createWriter.
@Override
protected IonWriter createWriter(final OutputStream out) throws IOException {
final IonMutableCatalog catalog = ((IonMutableCatalog) system().getCatalog());
final List<SymbolTable> symbolTables = new ArrayList<SymbolTable>();
int i = 1;
for (final List<String> symbols : SHARED_SYMBOLS) {
final SymbolTable table = system().newSharedSymbolTable("test_" + (i++), 1, symbols.iterator());
symbolTables.add(table);
catalog.putTable(table);
}
final _Private_IonManagedBinaryWriterBuilder builder = _Private_IonManagedBinaryWriterBuilder.create(_Private_IonManagedBinaryWriterBuilder.AllocatorMode.POOLED).withImports(importedSymbolResolverMode, symbolTables).withPreallocationMode(preallocationMode).withFloatBinary32Enabled();
if (lstAppendMode.isEnabled()) {
builder.withLocalSymbolTableAppendEnabled();
} else {
builder.withLocalSymbolTableAppendDisabled();
}
final IonWriter writer = builder.newWriter(out);
final SymbolTable locals = writer.getSymbolTable();
assertEquals(14, locals.getImportedMaxId());
return writer;
}
use of com.amazon.ion.IonWriter in project ion-java by amzn.
the class SymbolTableTest method testLocalSymbolTableAppendImportBoundary.
@Test
public void testLocalSymbolTableAppendImportBoundary() throws IOException {
String text = LocalSymbolTablePrefix + "{" + " symbols:[ \"s11\"]" + "}\n" + "1\n" + LocalSymbolTablePrefix + "{" + " imports:" + ION_SYMBOL_TABLE + "," + " symbols:[ \"s21\"]" + "}\n" + "null";
IonDatagram datagram = loader().load(text);
SymbolTable symbolTable = datagram.get(0).getSymbolTable();
assertSame(symbolTable, datagram.get(1).getSymbolTable());
symbolTable.intern("o1");
symbolTable.intern("a1");
// new symbols don't influence SIDs for existing symbols; they are appended
checkSymbol("s11", systemMaxId() + 1, symbolTable);
checkSymbol("s21", systemMaxId() + 2, symbolTable);
checkSymbol("o1", systemMaxId() + 3, symbolTable);
checkSymbol("a1", systemMaxId() + 4, symbolTable);
ByteArrayOutputStream out = new ByteArrayOutputStream();
IonWriter writer = IonBinaryWriterBuilder.standard().build(out);
datagram.writeTo(writer);
writer.close();
IonDatagram roundtripped = loader().load(out.toByteArray());
assertTrue(Equivalence.ionEquals(datagram, roundtripped));
}
use of com.amazon.ion.IonWriter in project ion-java by amzn.
the class SymbolTableTest method testWriteWithSymbolTable.
@Test
public void testWriteWithSymbolTable() throws IOException {
// this example code is the fix for a previous defect
// which resulted in a bad assertion in
// IonWriterUser.close_local_symbol_table_copy
IonDatagram data;
data = system().newDatagram();
insert_local_symbol_table(data);
append_some_data(data);
ByteArrayOutputStream out = new ByteArrayOutputStream();
IonWriter writer = system().newTextWriter(out);
writer.writeValue(data);
writer.close();
// dataMap.put("value", out.toByteArray());
byte[] bytes = out.toByteArray();
assertNotNull(bytes);
}
use of com.amazon.ion.IonWriter in project ion-java by amzn.
the class SymbolTableTest method testSymtabBinaryInjection.
@Test
public void testSymtabBinaryInjection() throws Exception {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
IonWriter writer = system().newBinaryWriter(baos);
writer.stepIn(IonType.LIST);
writer.writeNull();
writer.writeInt(10);
writer.writeFloat(10.0);
writer.writeTimestamp(new Timestamp(2013, 1, 1));
// this is where symbol table injection happens
writer.writeSymbol("abc");
writer.writeString("abc");
writer.stepOut();
writer.finish();
IonReader reader = system().newReader(baos.toByteArray());
assertEquals(IonType.LIST, reader.next());
reader.stepIn();
assertEquals(IonType.NULL, reader.next());
assertEquals(IonType.INT, reader.next());
assertEquals(IonType.FLOAT, reader.next());
assertEquals(IonType.TIMESTAMP, reader.next());
assertEquals(IonType.SYMBOL, reader.next());
assertEquals(IonType.STRING, reader.next());
assertEquals(null, reader.next());
reader.stepOut();
assertEquals(null, reader.next());
}
Aggregations